# 一些常用的用法
tpl = "i am {},age {},{}".format("seven", 16, "smelond")
print(tpl) # i am seven,age 16,smelond
tpl = "i am {},age {},{}".format(*["seven", 16, "smelond"])
print(tpl) # i am seven,age 16,smelond,注意,如果是列表要在前面加上*
tpl = "i am {0},age {1}, really {0}".format("seven", 16)
print(tpl) # i am seven,age 16, really seven
tpl = "i am {0},age {1}, really {0}".format(*["seven", 16])
print(tpl) # i am seven,age 16, really seven,列表需要加上*
tpl = "i am {name}, age {age}, really {name}".format(name="smelond", age=16)
print(tpl) # i am smelond, age 16, really smelond
tpl = "i am {name}, age {age}, really {name}".format(**{"name": "smelond", "age": 16})
print(tpl) # i am smelond, age 16, really smelond,注意,如果是字典需要加上两个*
tpl = "i am {0[0]}, age {0[1]}, really {1[2]}".format([1, 2, 3], [11, 22, 33])
print(tpl) # i am 1, age 2, really 33,列表里面的列表
tpl = "i am {:s}, age {:d}".format("smelond", 16)
print(tpl) # i am smelond, age 16
tpl = "i am {name:s}, age {age:d}".format(name="smelond", age=16)
print(tpl) # i am smelond, age 16
tpl = "i am {name:s}, age {age:d}".format(**{"name": "smelond", "age": 16})
print(tpl) # i am smelond, age 16,字典需要加上**
tpl = "numbers:{:b},{:o},{:d},{:x},{:X},{:%}".format(15, 15, 15, 15, 15, 15.87612)
print(tpl) # s:1111,17,15,f,F,1500.000000%
tpl = "numbers:{0:b},{0:o},{0:d},{0:x},{0:X},{0:%}".format(15)
print(tpl) # s:1111,17,15,f,F,1500.000000%
tpl = "numbers:{num:b},{num:o},{num:d},{num:x},{num:X},{num:%}".format(num=15)
print(tpl) # s:1111,17,15,f,F,1500.000000%