2022-08-18 学习Python-Day7
本帖最后由 wyh551202 于 2022-8-18 17:12 编辑第七天完成list的相关学习,P20~P26{:10_303:}
######################## P20
list=
print(list)
for each in list:
print(each)
list_len=len(list)
print(list)
print(list[-1])
print(list)
print(list)
print(list[:2])
print(list)
######################## P21
heros=['钢铁侠','绿巨人']
heros.append('黑寡妇')
heros.extend(['鹰眼','灭霸'])
s=
s =
print(s)
s=
s.insert(1,2)
s.insert(0,0)
s.insert(len(s),6)
print(s)
heros.remove('灭霸')
heros.pop(2)
heros.clear()
print(heros)
######################## P22
heros=['蜘蛛侠','绿巨人','黑寡妇','鹰眼','灭霸','雷神']
heros='钢铁侠'
heros=['武松','林冲','李逵']
print(heros)
nums=
nums.sort()
nums.reverse()
print(nums)
nums=
nums.sort(reverse=True)
print(nums)
nums_3=nums.count(3)
print(nums_3)
heros_lv=heros.index("绿巨人")
print(heros_lv)
heros='神奇女侠'
print(heros)
nums=
nums_index_3=nums.index(3,1,7)
print(nums_index_3)
nums_copy1=nums.copy()
nums_copy2=nums[:]
######################## P23
s=
t=
st=s+t
s3=s*3
print(st)
print(s3)
matrix=[,
,
]
for i in matrix:
print(i)
for each in i:
print(each,end=' ')
print()
print(matrix)
A=*3
for i in range(3):
A=*3
B=[*3]*3
A=1
B=1
print(A)
print(B)
x='cccc'
y='cccc'
xy=(x is y)
print(xy)
x=
y=
xy=(x is y)
print(xy)
######################## P24
x=
y=x
x=1
print(x)
print(y)
x=
y=x.copy()
x=1
print(x)
print(y)
x=
y=x[:]
x=1
print(x)
print(y)
x=[,
,
]
y=x.copy()
x =0
print(x)
print(y)
import copy
x=[,
,
]
y=copy.deepcopy(x)
x =0
print(x)
print(y)
######################## P25
oho=
for i in range(len(oho)):
oho=oho*2
print(oho)
oho=
oho=
print(oho)
x=
print(x)
y=
print(y)
code=
print(code)
matrix=[,
,
]
col2= for row in matrix]
print(col2)
diag= for i in range(len(matrix))]
print(diag)
diag= for i in range(len(matrix))]
print(diag)
######################## P26
B=[*3] *3
B =1
print(B)
A=*3
for i in range(3):
A=*3
A =1
print(A)
s=[*3 for i in range(4)]
print(s)
even=
print(even)
even=
print(even)
words=['Great','FishC','Brilliant','Excellent','Fantistic']
word_F==='F' ]
print(word_F)
matrix=[,
,
]
flatten=[col for row in matrix
for col inrow]
print(flatten)
flatten=[]
for row in matrix:
for col in row:
flatten.append(col)
print('s',flatten)
z=[x+y for x in 'fishc'
for y in 'FISHC']
print(z)
z=[ for x in range(10) if x%2==0
for y in range(10) if y%3==0]
print(z)
z=[]
for xin range(10):
if x%2 ==0:
for y in range(10):
if y%3==0:
z.append()
print('w',z)
我觉得列表表达式,换行容易理解
z=[ for x in range(10) if x%2==0
for y in range(10) if y%3==0]
要比
z=[ for x in range(10) if x%2==0 for y in range(10) if y%3==0]
容易看出
页:
[1]