qq_慕沐4443347
2021-05-19 16:02
a="Life{0} short{1} need{2}" b=a.format(" is",",you"," python") print(b) c='life{i},short{y},need{p}' is='is' you='you' python='python' d=a.format(i=is,y=you,p=python) print(d)
d的字符串模板应该是c 而不是a
a = "Life {0} short, {1} need {2}."
b=a.format("is","you","Python")
print(b)
c = 'life {i} short, {y} need {p}.'
i1 = 'is'
y1 = 'you'
p1 = 'python'
d = c.format(i=i1,y=y1,p=p1)
print(d)
is是保留字,不能作为变量名,换个名字吧
Python3 入门教程(新版)
154161 学习 · 1075 问题
相似问题