有两种方法可以从列表中删除指定的值:
my_list = [1, 2, 3, 4, 5] my_list.remove(3) print(my_list)
输出:
[1, 2, 4, 5]
my_list = [1, 2, 3, 4, 5] value_to_remove = 3 my_list = [x for x in my_list if x != value_to_remove] print(my_list)