I have a script I’m working on where I need to accept multiple arguments and then iterate over them to perform actions. I started down the path of defining a function and using *args. So far I have something like below:
def userInput(ItemA, ItemB, *args):
THIS = ItemA
THAT = ItemB
MORE = *args
What I’m trying to do is get the arguments from *args into a list that I can iterate over. I’ve looked at other questions on StackOverflow as well as on Google but I can’t seem to find an answer to what I want to do. Thanks in advance for the help.
To get your precise syntax:
You remove the
*in front ofargsin the assignment toMORE. ThenMOREbecomes a tuple with the variable length contents ofargsin the signature ofuserInputOutput:
As others have stated, it is more usual to treat
argsas an iterable:Output: