[root@ldpbzhaonan py]$ cat for01.py
name = ['1','2','3','4']
for i in name:
print("数字:", i)
[root@ldpbzhaonan py]$ python for01.py
数字: 1
数字: 2
数字: 3
数字: 4
遍历列表name中的元素,并打印出每个元素。
[root@ldpbzhaonan py]$ cat for02.py
for c in 'hello':
print("c = ", c)
[root@ldpbzhaonan py]$ python for02.py
c = h
c = e
c = l
c = l
c = o
也可以写双引号,和其他如三个单引号括起来,或者三个双引号括起来