0
How to give multiple integers as input to the function in the below code?
This is the code : def function(named_arg, *args): print(named_arg) print(args) function(1, 2, 3, 4, 5) I don't want to use the same values as arguments, Instead I want to give multiple integers as arguments by taking input. And also I would to test it with strings. Can someone explain how to do this?
3 Respostas
+ 2
Sai Krishna,
I have tried passing a `list`, `tuple`, `set` and `dict` to the function, and in each try the argument given was assigned into <named_arg>; <args> gets an empty tuple no matter what.
The only way I could imitate the behaviour was by slicing the argument (only `list` and `tuple` supports it) like this
data = [ 1, 2, 3, 4, 5 ]
function( data[ 0 ], *data[ 1 : ] )
But I don't think this was what you after ...
+ 1
Are the multiple integers for both <named_arg> and <args> or one of them?
Can you describe your goal in brief? it might help others to understand the problem and focus on the the relevant feedbacks ...
0
I want to 1 integer as input to named_arg and the remaining integers as input to *args