pyhton 下三个删除列表元素 remove,pop 和 del 方法的区别

#!/usr/bin/env Python3
__author__ = '未昔/angelfate'
__date__ = '2019/7/31 13:49'
# -*- coding: utf-8 -*-


# remove,pop和del 这三种方法都是list的删除方法,其中remove是针对可变列表的元素进行搜索删除,而pop和del是针对可变列表的下标进行搜索删除。

# 1. remove
# remove(item)方法是直接对可变序中的元素进行检索删除,返回的是删除后的列表,不返回删除值(返回None)
list1 = [0, 1, 3, 5, 8, 4]
a0 = list1.remove(4) #对列表元素进行搜索删除,而不是下标
print(a0)
print('list1:',list1)

# 2. pop
# pop(index)方法是对可变序列中元素下标进行检索删除,返回删除值
print('-'*50)
list2 = [0, 1, 3, 5, 8, 4]
a = list2.pop(4) # 对列表下表进行检索删除
print(a)
print('list2:',list2)
print('-'*50)
#3. del
# del(list[index])方法是对可变序列中元素下边进行检索删除,不返回删除值

list3 = [0, 1, 3, 5, 8, 4]
del list3[4]
print('list3:',list3)

pyhton 下三个删除列表元素 remove,pop 和 del 方法的区别