第二周——第四章操作列表作业
2018-03-17 22:10
351 查看
4-1 披萨pizzas=["mango","cheese","durian"]
for pizza in pizzas:
print("i like ",pizza,"pizza.")
print("i really love pizza.")输出i like mango pizza.
i like cheese pizza.
i like durian pizza.
i really love pizza.
4-2 动物animals = ["cow","sheep","pig"]
for animal in animals:
print(animal,"eats delicous.")
print("all of this can be food.")输出cow eats delicous.
sheep eats delicous.
pig eats delicous.
all of this can be food.4-10 切片
the first item in the list are ['sheep']
the first item in the list are ['pig']4-11 你的披萨和我的披萨
my_pizzas=["mango","cheese","durian"]
friend_pizza = my_pizzas[:]
my_pizzas.append("cannoli")
friend_pizza.append("ice cream")
print("my favorite pizzas are ",end='')
for pizza in my_pizzas:
print(pizza," ",end='')
print("\nmy friend's favorite pizzas are ",end='')
for pizza in friend_pizza:
print(pizza," ",end='')输出my favorite pizzas are mango cheese durian cannoli
my friend's favorite pizzas are mango cheese durian ice cream
4-12 使用多个for循环my_foods = ['pizza','falafel','carrot cake']
friend_foods = my_foods[:]
print('my favorite foods are: ')
for food in my_foods:
print(food,' ')
print('my friend\'s favorite foods are: ')
for food in friend_foods:
print(food,' ')输出my favorite foods are:
pizza
falafel
carrot cake
my friend's favorite foods are:
pizza
falafel
carrot cake
for pizza in pizzas:
print("i like ",pizza,"pizza.")
print("i really love pizza.")输出i like mango pizza.
i like cheese pizza.
i like durian pizza.
i really love pizza.
4-2 动物animals = ["cow","sheep","pig"]
for animal in animals:
print(animal,"eats delicous.")
print("all of this can be food.")输出cow eats delicous.
sheep eats delicous.
pig eats delicous.
all of this can be food.4-10 切片
animals = ["cow","sheep","pig"] print("the first item in the list are ",animals[0:1]) print("the first item in the list are ",animals[1:2]) print("the first item in the list are ",animals[2:3])输出the first item in the list are ['cow']
the first item in the list are ['sheep']
the first item in the list are ['pig']4-11 你的披萨和我的披萨
my_pizzas=["mango","cheese","durian"]
friend_pizza = my_pizzas[:]
my_pizzas.append("cannoli")
friend_pizza.append("ice cream")
print("my favorite pizzas are ",end='')
for pizza in my_pizzas:
print(pizza," ",end='')
print("\nmy friend's favorite pizzas are ",end='')
for pizza in friend_pizza:
print(pizza," ",end='')输出my favorite pizzas are mango cheese durian cannoli
my friend's favorite pizzas are mango cheese durian ice cream
4-12 使用多个for循环my_foods = ['pizza','falafel','carrot cake']
friend_foods = my_foods[:]
print('my favorite foods are: ')
for food in my_foods:
print(food,' ')
print('my friend\'s favorite foods are: ')
for food in friend_foods:
print(food,' ')输出my favorite foods are:
pizza
falafel
carrot cake
my friend's favorite foods are:
pizza
falafel
carrot cake
相关文章推荐
- Python学习第二周第二次作业——操作列表
- 第四章 操作列表(遍历列表)
- 《Python编程从入门到实践》_第四章_操作列表
- 【Python编程:从入门到实践】第四章:操作列表
- 第四章-操作列表
- (第二周作业:3、4章)有关列表的练习
- Python学习第二周第一次作业——列表简介
- 第二周作业——第四章动手试一试
- python 编程 入门到实践 第四章 列表操作和元祖 (课后题加原书)
- 第四天任务 (【基于Python编程从入门到实践】第四章 操作列表前四节 书本及动手试一试)
- 作业四——操作列表
- 《Python编程从入门到实践》_第四章_操作列表
- 第四天任务 (【基于Python编程从入门到实践】第四章 操作列表后两节 书本及动手试一试)
- python学习第四章操作列表部分课后练习自己尝试的代码
- 【《Python编程: 从入门到实践》习题答案--第四章:<list 列表操作>】
- python第二周作业——chapter 3,chapter 4 列表
- 【第二周】第四章作业
- POI实战-java开发excel详解(第四章 常用操作-下拉列表)
- Chapter4课后习题 列表Ⅱ操作列表(第二周Ⅱ)
- python中的列表,元祖,字典,等基本数据类型的操作