1.遍历列表
pets = [' cat ', ' dog ', 'bird']
for pet in pets:
printf(' A '+pet+' wound make a great pet!\n')
printf( 'Any of these animals wound make a great pet!\n')
2.列表解析与数值列表
square = [value**2 for value in range(1,18,3)] #列表解析
print(square)
print(max(square)) #打印最大值
print(sum(square)) #打印列表元素的和
3.列表切片
foods = ['pizza', 'falafel', 'carrot cake', 'cannoli' , 'ice cream']
f_food = foods[:2] #复制前两个元素
print(f_food)
h_food = foods[2:-1] #复制第三个元素之后的所有元素
print(h_food)