For example:
mytuple = ("Hello","World")
def printstuff(one,two,three):
print one,two,three
printstuff(mytuple," How are you")
This naturally crashes out with a TypeError because I'm only giving it two arguments when it expects three.
Is there a simple way of effectively 'splitting' a tuple in a tider way than expanding everything? Like:
printstuff(mytuple[0],mytuple[1]," How are you")
Kinda,... you can do this:
>>> def fun(a, b, c):
... print(a, b, c)
...
>>> fun(*(1, 2), 3)
File "<stdin>", line 1
SyntaxError: only named arguments may follow *expression
>>> fun(*(1, 2), c=3)
1 2 3
As you can see, you can do what you want pretty much as long as you qualify any argument coming after it with its name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With