定义: my_girl_friends=['aa','bb','cc',4,10,30] 或my_girl_friends=list(['aa','bb','cc',4,10,30]) # 获取类型 print(type(my_girl_friends)) #取第几个位置的取 print(my_girl_friends[2]) #取范围第几到第几的值 print(my_girl_friends[1:3]) # # 追加元素进去 my_girl_friends.append('oldboy') print(my_girl_friends) #pop按照默认弹出元素,从右往左弹 my_girl_friends.pop() my_girl_friends.pop() #pop按照索引弹出元素 my_girl_friends.pop(0) my_girl_friends.pop(0) my_girl_friends.pop(1) #remove按照值删除无素 my_girl_friends.remove('yuanhao') print(my_girl_friends) #得出列表元素个数 my_girl_friends.__len__() print(len(my_girl_friends)) #元素是否在列表 print('wupeiqi' in my_girl_friends) my_girl_friends=['a','b','c','d',4,10,30] #在某个具体位置插入元素 my_girl_friends.insert(1,'Sb') print(my_girl_friends) #清空列表 my_girl_friends.clear() print(my_girl_friends) #复制列表给别的变量 l=my_girl_friends.copy() print(l) #统计元素在列表中的个数 print(my_girl_friends.count('ee')) #列表追加元素 my_girl_friends.append('a1') my_girl_friends.append('a2') my_girl_friends.append('a3') print(my_girl_friends) # 列表追加多个元素 my_girl_friends.extend(['oldboy1','oldboy2','oldboy3']) print(my_girl_friends) #获取元素在列表中的下标 print(my_girl_friends.index('alex')) #列表反转 my_girl_friends.reverse() print(my_girl_friends) #列表中的值排序 l=[3,-1,5,2] l.sort(reverse=True) print(l)