5 usages of an asterisk (*) in Python
5 usages of an asterisk (*) in Python A star can be used in many scenarios in Python. Let’s start. Here the star helps to unpack iterables; called as unpacking operator. Double stars can be used to unpack a dictionary Merging two dictionaries can be done in many ways. Photo by Michael Kilcoyne on Unsplash 5 usages of an asterisk (*) in Python
Star and Python
1. Star as a multiplication operator
>>> 5 * 6
30
>>> * 2
>>> * 2
2. Stars as exponential operator
>>> 2 ** 3
8
3. Star in arguments
>>> :
...
... return f
...
>>>
1
2
3
is: 6
4. Stars in keyword arguments
>>> :
... return f
...
>>>
is: 6
5. Stars to update two dictionaries
>>> =
>>> =
>>> =
>>> = | # Union operator introduced recently
>>>
>>> # in place update
# as `y` value getting updated in `x`, `a` value getting overwritten from 1 to 10.
>>>
>>> =
>>>
# same key in two dictionaries will throw error
>>> =
:
1, in <>
, :
Related Articles