xl=[1,3,5,6,'中华人民共和国']
for each in xl:
print(each)
print(xl[0])
print(xl[4])
print(xl[-1])
print(xl[-2])
print(xl[0:5:1])
print(xl[0:5:2])
print(xl[::2])
print(xl[::-1])
print(xl)
print(xl[::])
print(xl[0:3])
print(xl[3:5])
print(xl[-5:-1])
xl.append('a')
xl.append(['b','c','d'])
xl[len(xl):]=['aa','bb']
print(xl)
xl.insert(6,'ins')
xl.insert(len(xl),'last')
print(xl)
xl.remove('a') #重复项目,只删除第一个,当还在时报错
xl.pop(6)
print(xl)
xl.clear()
print(xl)
xl1=[1,3,5,7,9,8,4]
xl1[1]=2
xl1[3:]=[20,15,12,12]
xl1.sort() #排序
xl1.reverse() #倒序
xl1.sort(reverse=True)
print(xl1)
tjs=xl1.count(12)
tjs=xl1.index(12)
tjs=xl1.index(12,3,6)
print(tjs)
xl1[xl1.index(12)]=13
print(xl1)
yxl=['a','b','c','f']
yxl_copy1=yxl.copy()
yxl_copy2=yxl[:]
print(yxl_copy1,yxl_copy2)
s=[1,2,3]
t=[4,5,6]
print(s+t)
print(s*3)
matrix=[[1,2,3],[4,5,6],[7,8,9]]
matrix=[[1,2,3],
[4,5,6],
[7,8,9]]
print(matrix)
for i in matrix:
for each in i:
print(each)
for i in matrix:
for each in i:
print(each,end=' ')
print()
print(matrix[1])
print(matrix[1][1])
A=[1]*3
for i in range(3):
A[i]=[0]*3
print(A)
B=[[0]*3]*3
print(B)
print(A[0] is A[1])
print(B[0] is B[1])
X=[1,2,3]
Y=X.copy() #浅拷贝
Z=X[:] #浅拷贝
import copy
x=[[1,2,3],[4,5,6]]
y=copy.copy(x) #浅拷贝
z=copy.deepcopy(x) #深拷贝
print(x,y)
x=[1,2,3]
for i in range(len(x)):
x[i]=x[i]*2
print(x)
x=[i*2 for i in x] #列表推导式
print(x)
_=[[x,y] for x in range(10) if x % 2 ==0 for y in range(10) if y % 3 == 0]
print(_)