1

I am writing some code that receives functions with variable numbers of arguments. I also have lists of those arguments (but the functions expect separate arguments, not one list). Is there a way to convert this list into arguments of a form that the functions might like (and sadly, they cannot just be converted to strings)?

1 Answer 1

8

Yes, just prefix the list with a * to unpack it:

args = [1, 2, 3]
foo(*args) # equivalent to foo(1, 2, 3)

More details available at the Python tutorial.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.