1. Creation of the list
Alist = [123, ' abc ', 4.56,[' inner ', ' list '], ' dchen ', ' Blank sapce '] #方刮号为列表, the array inside of it is added as its own case
2. Slicing operations on a list
Print (alist[0]) #选择列表第一个元素, the first element of the list in Python starts with 0
[' 123 ']
Print (Alist.index (123)) #找到元素在列表中的位置
0
Print (Alist[1:4]) #切片为数组中地址为1到4的元素 (4th digit not included)
[' Blank sapce ', ' dchen ', [' inner ', ' list '], 4.56, ' abc ', 123]
Print (Alist[:3]) #切片数组中地址为0到3的元素 (does not contain 3rd bit), the first bit does not give the specified number of points when the default is 0
[123, ' abc ', 4.56]
ALIST[3][1] #选择列表中子列表的元素
[' List ']
Alist[1:] #切片数组中地址为1到最后一位元素, the latter do not give the specified number of points when the default is the last
[' abc ', 4.56, [' Inner ', ' list '], ' dchen ', ' Blank sapce ']
ALIST[2:-1] #切片为数组中地址为2到最后一位的元素 (does not contain the last one)
[4.56, [' Inner ', ' list '], ' dchen ']
3. Add, delete, change the list
Append
Alist.append (345) #添加一个元素到列表中, added as last seat
Print (alist)
[123, ' abc ', 4.56, [' Inner ', ' list '], ' dchen ', ' Blank sapce ', 234]
Del
Del Alist[0] #选择删除列表中第一位元素
[' abc ', 4.56, [' Inner ', ' list '], ' dchen ', ' Blank sapce ']
Del alist #删除整个数组, this array will be emptied in memory
Pop
Alist.pop () #该删除方法在不给出任务参数时默认
[123, ' abc ', 4.56, [' Inner ', ' list '], ' dchen ']
Clear ()
Alist.clear () #和del The alist effect, empty the entire array and empty it inside
Remove
Alist.remove (4.56) #选择列表中的元素进行删除
Python (ii) List and operations