# 4-2 animals = ['cat', 'dog', 'tiger'] for animal in animals: print(animal) for animal in animals: print('A ' + animal + ' would make a great pet') print('Any of these animals has a mouth!') # 4-3 nums = list(range(1,21)) print(nums) # 4-4 nums1 = list(range(1,1000001)) print(nums1) # 4-5 print(min(nums1)) print(max(nums1)) aaa = sum(nums1) print(aaa) # 4-9 list = [value**3 for value in range(1,11)] print(list) # 4-10 print("The first three items in the list are:") for num in nums[:3]: print(num) print("The last three items in the list are:") for num in nums[-3:]: print(num) # 4-13 foods = ('fish', 'beef', 'mutton', 'vegetable', 'pork') for food in foods: print(food) # foods[0] = 'apple' foods = ('apple', 'beef', 'mutton', 'banana', 'pork') for food in foods: print(food)
3.14python作业
Python编程作业:遍历与操作列表
最新推荐文章于 2025-07-14 07:46:18 发布
这篇博客展示了Python编程中的几个基本操作,包括使用for循环遍历列表打印元素,计算列表最大值、最小值及总和,列表推导式生成立方数列表,以及切片操作显示列表的部分元素。此外,还演示了如何修改列表元素和重新定义列表。
1483

被折叠的 条评论
为什么被折叠?



