要删除Python列表中的数据,可以使用以下方法:
my_list = [1, 2, 3, 4, 5]
my_list.remove(3)
print(my_list) # Output: [1, 2, 4, 5]
my_list = [1, 2, 3, 4, 5]
del my_list[2]
print(my_list) # Output: [1, 2, 4, 5]
my_list = [1, 2, 3, 4, 5]
deleted_element = my_list.pop(2)
print(deleted_element) # Output: 3
print(my_list) # Output: [1, 2, 4, 5]
my_list = [1, 2, 3, 4, 5]
del my_list[1:3]
print(my_list) # Output: [1, 4, 5]
my_list = [1, 2, 3, 4, 5]
my_list.clear()
print(my_list) # Output: []