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是保留字,不能作为变量名,换个名字吧