Concatenating strings with mathematical symbols in Python 3 -


i created dictionary peoples' names such:

names = {"first": , "second": , "third":} 

what want call each name , combine them string, being separated plus sign. below tedious way of doing it:

str(names["first"]) + "+" + str(names["second"]) + "+" + str(names["third"]) 

this line larger module attempting create. tried following simplicity, resulted in syntax error:

str(names["first"] "%+d" + names["second"] "%+d" + names["third"]) 

is there way of simplifying above prints:

firstname+secondname+thirdname

in python 2 have use hacky

"{first}+{second}+{third}".format(**names) 

however, gingerplusplus points out, in python 3 can away **kwargs chicanery , instead use format_map

"{first}+{second}+{third}".format_map(names) 

Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Restarting Supervisor and effect on FlaskSocketIO -

php - Mongodb connectivity error -