4 Réponses
+ 5
If parameter is prefixed by asterisk then extra arguments would be grouped to a list.
Example:
def f(x, *args):
print(args)
f(1, 2, 3)
# prints:
# [2, 3]
Also two asterisks group keyword arguments to a dict.
+ 3
wonderful i was just wondering about this when i've seen this question thank you all!
+ 1
you can make the function accept a list which allows for any number of elements to be passed to it, but keep in mind, "infinite" is impossible as computers have limited memory
0
what if we made a generator with yield? Would it count as infinite arguments?