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

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -