1. 程式人生 > >python3 TypeError: cannot concatenate 'str' and 'int' objects)程式碼錯誤

python3 TypeError: cannot concatenate 'str' and 'int' objects)程式碼錯誤

python3 TypeError: cannot concatenate 'str' and 'int' objects)

 

是不是很奇怪???

我們進一步想想,print輸出的前面是字串組合,後面是列表(python),我們簡單點分開寫 :

使用 逗號 拼接  這樣:

my_foods = ['pizza','falafel','carrot cake','123','第一']
# 列印前三個切片
print("The first three items in the list are:",my_foods[:3])

嗯,就醬!

其實字串還有很多方式(方法)可以拼接,加油初學者,這中錯誤很常見(對我們Java學者來說^_^)