+ 4

How to make a function in python with infinite argumemts

python function

9th Aug 2018, 6:58 AM
Yash Goyal
Yash Goyal - avatar
4 Respostas
+ 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.
9th Aug 2018, 7:54 AM
wiad
+ 3
wonderful i was just wondering about this when i've seen this question thank you all!
9th Aug 2018, 8:52 AM
alfa6
alfa6 - avatar
+ 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
9th Aug 2018, 7:10 AM
hinanawi
hinanawi - avatar
0
what if we made a generator with yield? Would it count as infinite arguments?
10th Aug 2018, 6:06 PM
gogos kokos