添加元素 append()
在列表末尾添加新的对象
a = ["1","2","3","4"]
a.append(5)
print(a)
插入元素 insert()
#在开头插入一个对象 a = ["6","1","2","3","4"]
a = ["1","2","3","4"]
a.insert(0,6)
print(a)
#在结尾插入一个对象 a = ["1","2","3","4","5"]
a = ["1","2","3","4"]
a.insert(4,5)
print(a)
//用len()函数 有效的插入
a = ["1","2","3","4","5"]
a.insert(len(a),6)
print(a)
列表长度 len()
a = ["1","2","3","4","5"]
print(len(a))
删除元素 del
a = ["1","2","3","4","5"]
del a[4] #删除5
print(a)
list.pop()
移出列表中的一个元素(默认最后一个元素),并且返回钙元素的值
a = ["1","2","3","4","5"]
a.pop(0) #默认移除最后一个元素
print(a)
list.clear() 清空列表
a = ["1","2","3","4","5"]
a.clear()
print(a)
列表排序 reverse = True倒序排列
a = ["1","2","3","4","5"]
a.sort(reverse=True)
print(a)