问答详情
源自:3-7 Python的字符串format

这个是哪错了呢

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)

提问者:qq_慕沐4443347 2021-05-19 16:02

个回答

  • 37q
    2022-01-18 16:19:42

    d的字符串模板应该是c 而不是a

  • 37q
    2022-01-18 16:17:31

    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)

  • 三碗灬不过岗
    2021-05-19 17:15:25

    is是保留字,不能作为变量名,换个名字吧