python笔记 10.29

51 阅读1分钟
# 遍历字符串
for letter in "python":
    print(letter)

#遍历列表
f = ["apple","banana",2,["apple_1"]]
for i in f:
    print(i)

# rang()函数、 生成数字序列
#1、 rang(n)单参数,生成0到n-1的序列
for i in range(5):
    print("我在学习for循环")
    print(i)

# 累加计算
total = 0
for count in range(101):
    total = count + total
print("总和:", total)

#2、 range(a,b):双参数, 生成a到b-1的序列[a,b)
total = 0
for count in range(1,101):
    print(count)
    total = count + total
    print("总和:", total)

#3、 range(a,b.step) : 三参数,生成a到b-1、步长为step的序列
total = 0
for count in range(2,101,2):
    total = count + total
print("偶数总和:", total)

image.png

image.png