python里面使用for循环之后,更改列表,为什么会报错

2025-05-21 16:51:22
推荐回答(1个)
回答1:

friends = ['a', 'b', 'c', 'd']
for friend in friends:
    print(friend + ' i love you')
friends[0] = 'e'
print(friends)

以上程序没有错误。很明显,的你for写的有问题,元素名不能和列表同名。