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

这个感觉没问题,为啥有报错

template='{l} {i} {s},{y} {n} {p}.'

l1='life'

i1='is'

s1='short'

y1='you'

n1='need'

p1='python'


l=l1

i=i1

s=s1

y=y1

n=n1

p=p1


result=template.format(l,i,s,y,n,p)


print(result)


提问者:weixin_慕盖茨3126952 2021-09-15 21:34

个回答

  • 鹏鹏1209393
    2021-09-25 21:02:24

    template='{} {} {} ,{} {} {}.'
    l='life'
    i='is'
    s='short'
    y='you'
    n='need'
    p='python'
    result=template.format(l,i,s,y,n,p)
               

  • 慕粉1632435957
    2021-09-16 23:37:43

    template='{0} {1} {2},{3} {4} {5}.'
    
    l='life'
    
    i='is'
    
    s='short'
    
    y='you'
    
    n='need'
    
    p='python'
    
    result=template.format(l,i,s,y,n,p)

    {}这个格式里只能是顺序,不能是你填的lisynp之类的字母。你转两遍也没有意义