Reputation: 11325
Instead of having:
"my name is %s, and your name is %s" %(name, name)
is it possible to just have
"my name is %s, and your name is %s" %(name)
that would fill both %s with the name variable?
Upvotes: 1
Views: 58
Reputation: 599956
You can use a dictionary:
"my name is %(name)s, and your name is %(name)s" % {'name': name}
but better to use the new .format
method:
"my name is {name}, and your name is {name}".format(name=name)
or
"my name is {0}, and your name is {0}".format(name,)
Upvotes: 10
Reputation: 9909
how about
"my name is {name}, and your name is {name}".format(name=name)
Upvotes: 4