我不知道我的错误在哪里,有人可以帮助我吗? (蟒蛇)

时间:2020-07-31 03:54:11

标签: python xcode list variables rename

# 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. -----

2 个答案:

答案 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.