# 1. Create a list of all of the names
name = ["kaki", "helen", "makir", "pallu"]
print("My cousins are" + name+ "but helen is different than them.")
错误:
----- print("My cousins are" + name+ "but helen is different than them.")
TypeError: can only concatenate str (not "list") to str. -----
答案 0 :(得分:0)
尝试:
print("My cousins are " + str(name) + " but helen is different than them.")
答案 1 :(得分:0)
不与+串联,只需更改为逗号:
name = ["kaki", "helen", "makir", "pallu"]
print("My cousins are", name, "but helen is different than them.")
以下是输出:
My cousins are ['kaki', 'helen', 'makir', 'pallu'] but helen is different than them.