相关疑难解决方法(0)

为什么list.remove()的行为不像人们预期的那样?

from pprint import *

sites = [['a','b','c'],['d','e','f'],[1,2,3]]

pprint(sites)

for site in sites:
        sites.remove(site)

pprint(sites)
Run Code Online (Sandbox Code Playgroud)

输出:

[['a', 'b', 'c'], ['d', 'e', 'f'], [1, 2, 3]]
[['d', 'e', 'f']]
Run Code Online (Sandbox Code Playgroud)

为什么不是None,或者是空列表[]?

python

7
推荐指数
2
解决办法
7824
查看次数

标签 统计

python ×1