I am learning Python and came across variadic arguments. I don't understand the output that the following code produces:
_list = [11,2,3]
def print_list(*args):
for value in args:
a = value * 10
print(a)
print_list(_list)
When I run the program, I get:
[11, 2, 3, 11, 2, 3, 11, 2, 3, 11, 2, 3, 11, 2, 3, 11, 2, 3, 11, 2, 3, 11, 2, 3, 11, 2, 3, 11, 2, 3]
From what I understand, value holds one single element from the _list array, multiplying it by 10 would produce the list [110, 20, 30]. Why does the output differ?
print(args)and I think you'll see why.argsin your case is([11,2,3],)-- a length 1 tuple of lists.