遍历、创建数值列表、算术函数、列表解析:
#遍历列表
names = ['wangwu','ailun','zhangsan','dasha']
#临时变量可以指定任意名称,例name
for name in names:
print(name)
print(f"{name.title()} is very cute!")
print(f"遍历结束\n")
#生成一列数,下面会打印1到4
print(f"两个数:")
for value in range(1,5):
print(value)
#生成一列数,返回0到5
print(f"一个数:")
for value in range(6):
print(value)
#生成一列数,返回2,4,6,8,10
print(f"三个数,指定步长:")
for value in range(2,11,2):
print(value)
#创建数值列表,返回[1,3,5]
numbers = list(range(1,6,2))
print(numbers)
numbers = []
for number in range(1,6,2):
#numbers.append(number+1)
number_app = number + 1
numbers.append(number_app)
print(f"{numbers}\n")
#算数函数
digits = [1,2,3,4,5,6,7,8,9,0]
print(f"最小值:{min(digits)}\n最大值:{max(digits)}"
f"\n求和:{sum(digits