复制列表的方法:

  

lst = [1,2,3] 
lst1 = lst[:] # one way 
lst2 = list(lst) # another 

删除数据的正确方法:

num_list = [1, 2, 3, 4, 5] 
print(num_list) 
for item in num_list[:]: 
    if item == 2: num_list.remove(item) 
    else: 
        print(item) 
print(num_list)

作者:方小圆
链接:https://www.zhihu.com/question/49098374/answer/152953958
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-02
  • 2021-10-30
  • 2021-12-09
  • 2021-08-17
  • 2021-12-15
猜你喜欢
  • 2021-08-03
  • 2022-12-23
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
  • 2021-05-25
  • 2021-08-17
相关资源
相似解决方案