List with []
Express , List is a value , This value can be transferred to the function
a = ['1','2',3,4,['a','b']]
print(a[0])
print(a[1])
print(a[2])
print(a[3])
print(a[4])
a = ['1','2',3,4,['a','b']]
print(a[-1],a[-2],a[-3],a[-4],a[-5])
Note that the last one does not contain
a = ['1','2',3,4,['a','b']]
print(a[1:])
print(a[1:4])
a = ['1','2',3,4,['a','b']]
print(len(a))
a = ['1','2',3,4,['a','b']]
a[1] = 2
print(a[1:4])
a = ['1','2',3,4,['a','b']]
a = a + [5,6]
print(a)
a = ['1','2',3,4,['a','b']]
del a[1]
print(a)
a = [0,1,2,3]
for i in a :
print(i)
Returns the subscript index()
If multiple values appear , The first subscript is returned
a = [0,1,2,3]
print(a.index(0))
print(a.index(1))
print(a.index(2))
print(a.index(3))
a = [0,1,2,3]
a.append(5)
a.append(6)
print(a)
insert() Support arbitrary position insertion
a = [0,1,2,3]
a.insert('5',4)
a.insert('6',5)
print(a)
remove If you want to remove elements from the list , An element appears many times , Only the first
a = [0,1,2,3,1]
a.remove(1)
print(a)
sort Sort , Can order , It can also be in reverse order
Don't sort lists with both numbers and strings
The order
a = ['q','w','w','w','r','t']
# according to ASCLL Sort code
a.sort()
print(a)
The reverse
a = ['q','w','w','w','r','t']
a.sort(reverse = True)
print(a)