What does that asterisk in line 1 mean? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What does that asterisk in line 1 mean?

def foo(a, *b): return a * b c = foo(1 ,2 ,3) print(c) Other than the question mention on the title, I would also like to know why the output is (2, 3) instead of 6?

2nd Apr 2019, 2:42 PM
Sergio Chan
Sergio Chan - avatar
1 Answer
0
The asterisk means that it will take the remaining items (if any+) in the iterable and save them in b. In the example above, input is (1,2,3), thus: a = 1 b = (2,3) 1*(2,3) = (2,3) Output: (2,3) I wish you success!
2nd Apr 2019, 6:03 PM
Luis SepĂșlveda
Luis SepĂșlveda - avatar