(Nov-14-2020, 07:46 PM)zarox Wrote: Is this method as "correct" as *args and *kwargs?
It depend what you want to achieve. This is the correct method if you want to pass one argument (it may be tuple). It will take one and only one argument (it may or may not be the type you expect).
In your initial post you were asking something different, or at least I understood that you ask about arbitrary number of positional arguments - i.e. when you don't know in advance how many arguments you will get or want to allow arbitrary number. In your post:
(Nov-14-2020, 04:21 PM)zarox Wrote: I can call function(1,2,3)Here you don't pass one tuple, but 3 positional arguments.
def spam(foo): print(foo) foo = (1, 2, 3) spam(foo) spam(1, 2, 3)
Output:(1, 2, 3)
Traceback (most recent call last):
File "***", line 6, in <module>
spam(1, 2, 3)
TypeError: spam() takes 1 positional argument but 3 were given
*args, **kwargs is often used in more complex cases, e.g. OOP with class inheritance
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