📜  丢弃 vs 删除 python 代码示例

📅  最后修改于: 2022-03-11 14:45:55.627000             🧑  作者: Mango

代码示例1
list = [1, 2, 3, 4, 5]
list.remove(0)    #removes element in specified position
print(list)
>> [2, 3, 4, 5]
list.discard(2)    #discards element if found in iterable (in list in this case) ;)
print(list)
>> [3, 4, 5]