第7句哪里錯(cuò)了是什么問(wèn)題,想法思路錯(cuò)了嗎
# Enter a code
template = 'Life {0} ,you {1}.'
result = template.format('is short','need Python')
print(result) #
template ='Life {a},you'
a = 'is short'
b ='need Python'
result = template.format(a = is short,b = need Python)
print(result)#
2022-02-18
我舉個(gè)栗子,你看能不能發(fā)現(xiàn)你原本的錯(cuò)誤:
如果我這里要輸出‘I am smart,as well as handsome’
我應(yīng)該這樣寫(xiě):
可以看出,format中的寫(xiě)法應(yīng)該是使temple中”{ }”里的名“=”要插入的字符串所對(duì)應(yīng)的變量名
如果“{ }”中的名和變量名相同,就會(huì)沖突了