# Python 3 Basic syntax
List Index
0-1 represents the last
0list can be placed in a variety of types
# -*-coding:utf-8-*-names = ['Mark'coloe', 1,2,3,4,5,3.14, True]print (type (names))print(names) Print(names[1])print(names[0])print(names[-1])
list nesting uses
1 #-*-coding:utf-8-*-2names = ['Mark','Coloe', ['I',' Love','poedu','!',],1,2,3,4,5,3.14,true, ['I',' Love','Mark','!',]]3 Print(type (names))4 Print(names)5 Print(Names[2])#nested list6 Print(Names[-1])#nested list7 Print(Names[-1][1], names[2][2])#gets the value of the nested list and outputs
List append[]
Join at the end
1 #-*-coding:utf-8-*-2names = ['Mark','Coloe', ['I',' Love','poedu','!',]]3 Print(names)4Names.append ('Google')5 Print(names)6Names.append ('Baidu')7 Print(names)8Names.append ('poedu')9 Print(names)
List insert[]
Specify location Insertion
Parameter 1: Position
Parameter 2: Inserted value
1 #-*-coding:utf-8-*-2names = ['Mark','Coloe', [' Love','poedu','!',]]3 Print(names)4Names.insert (1,'Carrot')5 Print(names)6Names.insert (4,'So Much!')7 Print(names)
list Clear ()
Empty index
1 #-*-coding:utf-8-*-2names = ['Mark','Coloe', [' Love','poedu','!',]]3Names.insert (1,'Carrot')4Names.insert (4,'So Much!')5 names.clear ()6 Print(names)
list copy ()
Copy Index
1 #-*-coding:utf-8-*-2names = ['Mark','Coloe', [' Love','poedu','!',]]3other =names.copy ()4 Print(names)5 Print(Other)
list pop ()
Delete End of index
Parameter 1: Delete data at the specified location
It feels like a stack.
1 #-*-coding:utf-8-*-2names = ['A','B','C','D','E','F','G','H','I','J','K',]3 Print(names)4 Names.pop ()5 Print(names)6 names.pop (0)7 Print(names)8Names.pop (3)9 Print(names)
Python tuples
A python tuple is similar to a list, except that the elements of a tuple cannot be modified.
Tuples use parentheses, and the list uses square brackets.
Tuple creation is simple, just add elements in parentheses and separate them with commas.
1#-*-coding:utf-8-*-2Names = ('A','B','C','D','E','F','G','H','I','J','K')3 print (type (names))4 print (names)5 #元祖访问6Print (names[0])7Print (names[1:5])8Print (names[6:])9Print (names[6:-1])
001 Python List Index