names = ["Aaron", "Alex", "James", "Meihengfan"]
Names2 = [1,2,3,4,5]
Print (names)
Property Check
Print (len (names)) #确定列表的长度
Max/min
If Arron in Names n
#print (names) #列出列表的内容
Print (names[3]) #访问列表中第4个值
Print (Names[1:3]) #访问列表中从第2个到第3个的值
Print (names[-1]) #访问列表中的最后一个值
Print (Names[:-2]) #访问列表中的所有值, but remove all values from the penultimate and subsequent
Print (names[-3:]) #访问列表中倒数第一个到倒数第三个的值
Print (names[0],names[3]) #注意取多个值的时候, cannot directly write the subscript together, need to write in this way
Print (Names[::2]) #打印列表, but with 2 as the step, is to skip the cut, you can also change the step according to demand
Print (Names.index ("James")) #查找列表中james这个元素的下标
Names.append ("Jack") #在列表末尾插入一个元素
Names.insert (1, "Fanheng") #把fanheng插入到第二个位置那里
NAMES[2] = "Liming" #把第三个位置的元素改成liming
Names.remove ("Liming") #把元素liming从列表中删除
Del names[2] #把第三个元素删除, you must know the index of the element
#del names #直接删除列表
Names.pop () #默认删除列表末尾的元素, of course, you can also directly specify the index of the element to eject a specified element, and let you wait for it to continue to use it
#每当你使用pop时, the elements that are ejected are no longer in the list.
#pop把一个元素从列表中弹出来了, the value being bounced can be directly assigned to other variables, such as:
Popend_name = Names.pop ()
Print (Popend_name)
#names. Clear () #清空列表, hazardous operation, please use caution
#其它操作
#names. Reverse () #把列表反转, is to reverse the original order completely.
#排序
#names. Sort () #把列表永久性的排序
Print (sorted (names)) #对列表进行临时性的排序
#合并列表
Names.extend (Names2) #把names2的东西合并到names里面
Print (names)
#列表去重
Scenario One: With Set ()
Scenario Two: Use the function for ... if ... append ...
Python base list additions and deletions