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
moyutime:本文仅是学习心得,观点仅供参考,祝愿读者学习途中快乐且不断有所收获。