个人学习自用,各位可随便取
#4-1 food
food = ['tomato' , 'orange' , 'banana']
for foods in food:
print("i like " + foods.title() + " .")
print("i really like banana .")
# 4-2 动物
animals = ['dog' , 'fish' , 'pet']
for animal in animals:
print("a " + animal.title() + " make a great pet")
print("any of these animals would make a great pet!")
# 4-3 数到20
numbers = list(range(1,21))
print(numbers)
# 4-4 一百万
numbers = list(range(1,100))
print(numbers)
# 4-7 3的倍数
numbers = [value*3 for value in range(1,11)]
print(numbers)
# 4-9 立方解析
numbers = [value**3 for value in range(1,11)]
print(numbers)
# 4-10 切片
foods = ['tomato' , 'orange' , 'banana' , 'apple' , 'ice cream']
print("the first three items in the list are :")
for food in foods[:3]:
print(food)
print("three items from the middle of the list are :")
for food in foods[1:4]:
print(food)
print("the last three items in the list are :")
for food in foods[2:]:
print(food)