I have a string:
testString = """ My name is %s
and I am %s years old
and I live in %s"""
I have code that finds these three strings that I want to input into testString. How do I do that? In Java I would've done:
return String.format(testString, string1, string2, string3)
Is there an equivalent in Python?
this is the version using %
:
print """ My name is %s
and I am %s years old
and I live in %s""" % ('tim', 6, 'new york')
and this my preferred version:
testString = """ My name is {}
and I am {} years old
and I live in {}""".format(string1, string2, string3)
you may want to read https://docs.python.org/3.4/library/string.html#string-formatting .