demo_ref_string_format2.py:
#named indexes: txt1 = "My name is {fname}, I'm {age}".format(fname = "John", age = 36) #numbered indexes: txt2 = "My name is {0}, I'm {1}".format("John",36) #empty placeholders: txt3 = "My name is {}, I'm {}".format("John",36) print(txt1) print(txt2) print(txt3)
➜ begtut>python demo_string_format2.py
My name is John, I'm 36
My name is John, I'm 36
My name is John, I'm 36