What’s the point of positional parameters? Can’t I just put a tuple as an argument for the parameter? It does the same thing.
It better. Positional arguments or tuple are both immutable sequences.
So what’s the point in having positional arguments if everything can be done with tuples as well?
If functions have special syntax dedicated to them, and multiple arguments is common, then doesn’t it make sense for the syntax dedicated to functions to spare you the trouble of unpacking the values from a container?
The return value on the other hand is a single value, and if there are several things you’d want to send back then you’d use a container for that. You’d have to unpack that on the receiving end regardless, so having multiple return values wouldn’t help.
shout_strings(“hi”, “what do we have here”, “cool, thanks!”)
when using * , if we are using a tuple for arguments. Isn’t there should be two parenthesis
Could we get a look at that function, please?
The sequence is packaged when given as an argument so extra structure is not needed. It is unpacked by the splat operator in the parameter.
>>> a = 1, 2, 3, 4 >>> [*a] [1, 2, 3, 4] >>> m, n, o, p = a >>> m 1 >>> n 2 >>> o 3 >>> p 4 >>> for x in a: print (x) 1 2 3 4 >>>