What is Double Asterisk (**) in python ?

Answer : In Python ** is an exponential operator……

** in python

  • In Python ** is an exponential operator.The double asterisk form of **kwargs is used to pass a keyword, variable-length argument dictionary to a function. Again, the two asterisks (**) are the important element here, as the word kwargs is conventionally used, though not enforced by the language.
  • Like *args, **kwargs get however several arguments you would like to supply into it. Though **kwargs differs from *args in that you will need to assign keywords.

First, let’s simply print out the **kwargs arguments that we pass to a function. We’ll create a short function to do this:

print_kwargs.py

def print_kwargs(**kwargs):
print(kwargs)

Next, we will call the function with some other keyword arguments passed into the function:

Sample Code:

[pastacode lang=”python” manual=”def%20print_kwargs(**kwargs)%3A%0A%20%20%20%20%20%20%20%20print(kwargs)%0Aprint_kwargs(kwargs_1%3D%22Shark%22%2C%20kwargs_2%3D4.5%2C%20kwargs_3%3DTrue)” message=”” highlight=”” provider=”manual”/]

Output :

[pastacode lang=”python” manual=”%7B’kwargs_3’%3A%20True%2C%20’kwargs_2’%3A%204.5%2C%20’kwargs_1’%3A%20’Shark’%7D” message=”” highlight=”” provider=”manual”/]
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like