format()
的使用day = "三"
weather = "晴朗"
test = "今天是星期{},天气{}".format(day, weather)
print(test)
>>> 今天是星期三,天气晴朗
name = "张三"
age = 21
thing = "去上学"
res = "姓名:{0},年龄:{1},{0}今天{2}了".format(name,age,thing)
print(res)
>>>姓名:张三,年龄:21,张三今天去上学了
name = "张三"
age = 21
thing = "去上学"
res = "姓名:{zz},年龄:{xx},{zz}今天{cc}了".format(zz=name,xx=age,cc=thing)
print(res)
>>>姓名:张三,年龄:21,张三今天去上学了