Python的list简单练习

L=[1,2,3,9,4,'233',5,6,7,9,'233','233']
L2=['个','数','企']
L.append(45)
L.insert(2,77)
L[2]=66
print(L)
L.remove(66)
del L[0]
L.pop(2)
print(L)
print(L[2:4])
print(L[-4:-1])
print(L.index(45))
print(L[L.index(45)])
print(L.count('233')) #计数3在list中有几个
#引入别的列表
L.extend(L2)
print(L)

for i in range(3):
print('-----------------------------')

import copy
A=['1','2','3',['你','好','!'],'4','5']
#L2=L.copy()
A2=copy.deepcopy(A)
A[1]='6'
A[3][1]='hao'

print(A)
print(A2)

a = 1
b = a
a = 2
print(b)
a = [1,2,3]
b = a
a[0] = '123'
print(b)

猜你喜欢

转载自www.cnblogs.com/work-for-who/p/9123368.html
今日推荐