第7句哪里錯了是什么問題,想法思路錯了嗎
# 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
我舉個栗子,你看能不能發現你原本的錯誤:
如果我這里要輸出‘I am smart,as well as handsome’
我應該這樣寫:
可以看出,format中的寫法應該是使temple中”{ }”里的名“=”要插入的字符串所對應的變量名
如果“{ }”中的名和變量名相同,就會沖突了