1

How I can dynamically pass arguments to format function of string, Below is sample, Here my "text" string would be dynamic and it may have n number of dynamic argument, Function will receive a tuple, I want to fit the tuple value in the dynamic locations. But the format function is not working with tuple.

text = "Good {0}, {1} !!!"
def sayHello(*args):
    return "Good {0}, {1} !!!".format(args)
print sayHello('Morning', "Tom")

1 Answer 1

3

Just add another asterisk when using format

text = "Good {0}, {1} !!!"
def sayHello(*args):
    return "Good {0}, {1} !!!".format(*args)
print (sayHello('Morning', "Tom"))
#Good Morning, Tom !!!
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.