What does the Double Star operator mean in Python?

PythonServer Side ProgrammingProgramming

For numeric data types double asterisk (**) is defined as exponentiation operator

>>> a=10; b=2
>>> a**b
100
>>> a=1.5; b=2.5
>>> a**b
2.7556759606310752
>>> a=3+2j
>>> b=3+5j
>>> a**b
(-0.7851059645317211+2.350232331971346j)

In a function definition, argument with double asterisks as prefix helps in sending multiple keyword arguments to it from calling environment

>>> def function(**arg):
    for i in arg:
      print (i,arg[i])

>>> function(a=1, b=2, c=3, d=4)
a 1
b 2
c 3
d 4


raja
Published on 06-Feb-2018 07:07:38
Advertisements