0

Doubt in the function argument in python

What is the difference between a and *a in the argument variable? I have seen this many a times but couldn't understand it. Can anyone explain in detail?

11th Apr 2020, 1:36 PM
Abhiraj Ghumare
Abhiraj Ghumare - avatar
5 Answers
+ 2
I made good example def log(*a): print(*a, file=sys.stderr) log(2,"banana") log(2,4,10,20) Operator * allows to call method with as many parameters as you want without wrapping them into array or tuple like this log((2,4,10,20)) Python does it for you
11th Apr 2020, 1:50 PM
Stephan
Stephan - avatar
+ 2
def myfunct(*args): for x in args: print(x) one = 1 two = 2 three = 3 four = 4 myfunct(one, two, three, four) five = 5 myfunct(one, two, three, four, five) it scoops up all the function arguments into a tuple so you can then iterate over it..
11th Apr 2020, 1:41 PM
rodwynnejones
rodwynnejones - avatar
0
Thank you
11th Apr 2020, 2:06 PM
Abhiraj Ghumare
Abhiraj Ghumare - avatar
0
Try to run my example without one of * for better understanding
11th Apr 2020, 2:08 PM
Stephan
Stephan - avatar
0
Ok
11th Apr 2020, 2:08 PM
Abhiraj Ghumare
Abhiraj Ghumare - avatar