Py学习  »  Python

为什么我的列表没有被python覆盖?[副本]

Challa Sai Bhanu Teja • 5 年前 • 1372 次点击  

这个问题已经有了答案:

List = ["I?", "Can", "!Not", "Do.", "It"]
l=[]
BadChars = ["?", "!", "."]
for i in List:
    for j in BadChars:
        if j in i:
            i=i.strip(j)
    l.append(i)
print(l)
print(List)

输出:

enter image description here

正如您在输出中看到的,即使写入i=i.strip(j),列表也不会被覆盖。发生什么事了?事先谢谢。我刚开始学巨蟒,所以这个问题可能很愚蠢。 这个问题在我解决堆栈溢出子列表中的更改字符时在我的头脑中提出。我的问题是“为什么list和l有不同的值?”

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38266
 
1372 次点击  
文章 [ 3 ]  |  最新文章 5 年前