I don’t understand how to interpret this ? And why answer is 3? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I don’t understand how to interpret this ? And why answer is 3?

Def function (a, *b ) : Print (list(b)[1]) Function (5,4,3,2,1)

16th Oct 2020, 6:24 PM
Curious Ant
Curious Ant - avatar
3 Answers
+ 9
The issue is not tuple unpacking here but function arguments. You can find more in this short tutorial: https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/4409/?ref=app
16th Oct 2020, 6:40 PM
Lothar
Lothar - avatar
16th Oct 2020, 6:26 PM
[][]
+ 2
*b means *args in other words all not mentioned arguments of function is collected as list named args (this is convention, in your case b instead of args) so, a = 5 b = [4,3,2,1] and function just prints 1st elem of list. i.e b[0]=4 b[1]=3 b[2]=2 b[3]=1
16th Oct 2020, 6:29 PM
Shadoff
Shadoff - avatar