(純小白)為什么運(yùn)行錯(cuò)誤呢?
print('第一種方式, 普通方式')
template = 'Life is short,{}'
a = 'you need Python'
result = template.format(a)
print(result)
print('第二種方式, 指定順序')
template = 'life {0} short,{1}need {2}.'
result = template.format('is','you','Python')
print(result)
2021-08-20
結(jié)合2-2 第一個(gè)Python程序的練習(xí)去看,應(yīng)該是Python默認(rèn)是以ASCII作為編碼方式,如果在自己的Python源碼中包含了中文需要在第一行加上:
#coding=utf-8
加上后就運(yùn)行成功啦
2021-08-16
result = template.format()這個(gè)只能每次接收一個(gè)字符串