5 Uses of Asterisks in Python
The asterisk, which is known as the multiplication operator, is a commonly used symbol in all programs. It could be enough for us to use it just as a multiplication operator. However, if you are serious about to become a Python expert. It’s time to know how useful and powerful the asterisk is in Python.
This post will explain 5 usage scenarios of asterisks with most understandable examples, from elementary to profound.
Use 1: Multiplication or Exponentiation Operator
The simplest use is to exploit asterisks as infix operators:
- Single
*
for the multiplication operation. - Double
**
for the exponentiation operation.
>>> 2*3
>>> 6>>> 2**3
>>> 8
Use 2: To Receive an Unlimited Number of Arguments
A function is not necessarily to receive a fixed number of arguments if you need more flexibility or even not sure how many arguments will be passed. Here is the asterisks’ showtime.