0

Why do we need * in (*bar) in the code below?

def foo(a,b,c): print(a,b,c) bar=(3,14,15) foo(*bar)

9th Jun 2020, 2:49 AM
Ali Rezaei
Ali Rezaei - avatar
3 odpowiedzi
+ 2
its more like: def foo(*bar): for b in bar: print(b, end=' ') Input: foo(1,3,5,7) foo(2,4) Output: 1 3 5 7 2 4 And for what happens when its not there, try it out and see
9th Jun 2020, 3:09 AM
Slick
Slick - avatar
+ 1
* allows you to pass an arbitrurary amount of arguments. The variable bar is usually: args (as in arguments)
9th Jun 2020, 2:58 AM
Slick
Slick - avatar
0
Slick So what happens it it is not used here?
9th Jun 2020, 3:04 AM
Ali Rezaei
Ali Rezaei - avatar