0

How can I have *args and another parameter after?

Like let's say I have an array with numbers [1, 2, 3, 4, etc.] and I want to get all of them except the last one in the *args and the last one in another arg. How can I do that?

22nd Apr 2021, 9:01 AM
Alexander Shestakov
Alexander Shestakov - avatar
4 odpowiedzi
+ 4
args = args[:-1] # every arg but the last args.append(<whatever>) # put whatever on the end
22nd Apr 2021, 9:18 AM
Slick
Slick - avatar
+ 1
According to the Tutorial, Python Core 95.1: The parameter *args must come after the named parameters to a function. The name args is just a convention; you can choose to use another.
22nd Apr 2021, 9:19 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Rik Wittkopp I just saw that but thank you.
22nd Apr 2021, 9:20 AM
Alexander Shestakov
Alexander Shestakov - avatar
+ 1
Slick Thank you
22nd Apr 2021, 9:20 AM
Alexander Shestakov
Alexander Shestakov - avatar