4-2
animals=['dog','cat','cow']
for animal in animals:
print(animal)
print('A '+animal.title()+' would make a great pet.\n')
print('Any of these animals would make a great pet!\n')

4-5
array=[]
for value in range(1,1000001):
array.append(value)
print(min(array))
print(max(array))
print(sum(array))

4-10
array=['a','b','c','d','e']
print('The first three elements:')
print(array[0:3])
print('Three elements from middle of the list:')
print(array[1:4])
print('The last three elements of list:')
print(array[-3:])

Python编程实例
本文通过几个简单的Python编程实例展示了如何遍历列表并打印元素、生成一个包含特定范围数值的列表及进行基本的数学运算。这些实例有助于理解Python的基本语法和流程控制。
680

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



