python笔记:数组

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(_)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值