A dictionary can be passed to format()
, each key name will become a variable for each associated value.
dict = {'string1': 'go',
'string2': 'now',
'string3': 'great'}
multiline_string = '''I'm will {string1} there
I will go {string2}
{string3}'''.format(**dict)
print(multiline_string)
Also a list can be passed to format()
, the index number of each value will be used as variables in this case.
list = ['go',
'now',
'great']
multiline_string = '''I'm will {0} there
I will go {1}
{2}'''.format(*list)
print(multiline_string)
Both solutions above will output the same:
I'm will go there
I will go now
great