This is not using tuple as argument, but pass arbitrary number of arguments. If you pass tuple as argument it will be considered one argument, not multiple (unless you unpack it).
Here is example to show the difference when you pass a tuple and when you unpack tuple into multiple arguments
def spam(*args): print(type(args), args) spam(1, 2, 3) spam('a', 'b')
Output:<class 'tuple'> (1, 2, 3)
<class 'tuple'> ('a', 'b')
You can also have keyword arguments, so, you can dodef spam(*args, **kwargs): print(type(args), args) print(type(kwargs), kwargs) spam(1, 2, 3, foo='eggs', bar='spam') spam('a', 'b')
Output:<class 'tuple'> (1, 2, 3)
<class 'dict'> {'foo': 'eggs', 'bar': 'spam'}
<class 'tuple'> ('a', 'b')
<class 'dict'> {}
Note that args
and kwargs
are names by convention used in such case. I would advise to stick to these.Here is example to show the difference when you pass a tuple and when you unpack tuple into multiple arguments
def spam(*args, **kwargs): print(type(args), args) print(f'Number of positional arguments: {len(args)}') print(type(kwargs), kwargs) some_tuple = (1, 2, 3) spam(some_tuple, foo='eggs', bar='spam') spam(*some_tuple, foo='eggs', bar='spam')
Output:<class 'tuple'> ((1, 2, 3),)
Number of positional arguments: 1
<class 'dict'> {'foo': 'eggs', 'bar': 'spam'}
<class 'tuple'> (1, 2, 3)
Number of positional arguments: 3
<class 'dict'> {'foo': 'eggs', 'bar': 'spam'}
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs