4-2 动物
pets=['cat','dog','bunny']
for pet in pets:
print(pet)
for pet in pets:
print('a '+pet+' would make a great pet')
print("Any of these animals would make a great pet!")
4-3 数到20
for num in range(1,21):
print(num)
4-6 奇数
for num in range(1,20,2):
print(num)
4-9 列表解析
num=[value**3 for value in range(1,11)]
print(num)
4-10 切片(以4-9的程序为基础)
num=[value**3 for value in range(1,11)]
print(num)
print("The first three items in the list are:")
print(num[:3])
print("Three items from the middle of the list are:")
print(num[3:6])
print("The last three items in the list are:")
print(num[7:])