+ 1
is the class type of Arbitrary Argument, (*args) in python 'list' or 'tuple'?
x, *args= 1,2,3 print(type(args)) # <class 'list''> def print_type(*args): print(type(args)) # <class 'tuple' print_type(1,2,3) The first print statement outputs 'class list' while the second outputs 'class tuple'. Why is that?
2 Answers
+ 4
Because *args gives you a tuple. anything in a sequence without explicitly placing parenthesis around them makes it a list rather than tuple.
If you want 1,2,3 as a tuple, check:
type((1,2,3))
Instead of printing the type, try printing them out and see for yourself
+ 3
Slick tnx a lot.