python之确定循环for

确定循环for

格式

for <var> in <sequence>:
    <content>

例子1

for i in range(3):
    print(i)
# 0
# 1
# 2

例子2

for i in [1, 3, 'a', '我爱你中国']:
    print(i)
# 1
# 3 
# a
# 我爱你中国

例子3

for i in 'forloop':
    print(i)
# f
# o
# r
# l
# o
# o
# p

例子4

a = 'forloop'
for i in a:
    print(i)
# f
# o
# r
# l
# o
# o
# p
posted on 2021-01-18 23:09  摸鱼time  阅读(49)  评论(0编辑  收藏  举报