I have written a code to understand the use of bare "*" in function argument list and I am sharing that with everyone.
I have created a function called myFunction having three arguments "a","b" and "c". I placed "*" between a and b
Non-positional argument means that the order of that argument during function call is not fixed and value is passed using key of that argument.
The arguments before * are positional arguments and values are passed to these argument without keys.
Another code:
I have created a function called myFunction having three arguments "a","b" and "c". I placed "*" between a and b
def myFunction(a,*,b,c): print('a',a) print('b',b) print('c',c) myFunction(10,c=20,b=12)Output:
Output:a 10
b 12
c 20
The "*" in argument list of a function ensures that the arguments after that are Non-positionalNon-positional argument means that the order of that argument during function call is not fixed and value is passed using key of that argument.
The arguments before * are positional arguments and values are passed to these argument without keys.
Another code:
def myFunction(*,a,b,c): print('a',a) print('b',b) print('c',c) myFunction(a=10,c=20,b=12)