python列表生成式&字典

#Copy &deepcopy

from copyimport deepcopy

list1=[1,2,3,4]

list2=['a','b',list1]

list3=list2.copy()

#['a', 'b', [1, 2, 3, 4]]

list4=deepcopy(list2)

#['a', 'b', [1, 2, 3, 4]]

list1=[1,2]

print(list3)

#['a', 'b', [1, 2, 3, 4]]

print(list4)

#['a', 'b', [1, 2, 3, 4]]

list1.append('c')

print(list1)

#[1, 2, 'c']

print(list3)

#['a', 'b', [1, 2, 3, 4]]

print(list4)

#['a', 'b', [1, 2, 3, 4]]

list1=[i*ifor iin range(1,16)if i%2!=0]

print(list1)

#[1, 9, 25, 49, 81, 121, 169, 225]

list3=[i*jfor iin range(1,10)for jin range(i,10)]

print(list3)

#[1, 2, 3, 4, 5, 6, 7, 8, 9, 4, 6, 8, 10, 12, 14, 16, 18, 9, 12, 15, 18, 21, 24, 27, 16, 20, 24, 28, 32, 36, 25, 30, 35, 40, 45, 36, 42, 48, 54, 49, 56, 63, 64, 72, 81]


python列表生成式&字典_第1张图片





python列表生成式&字典_第2张图片

你可能感兴趣的:(python列表生成式&字典)