語法:
for 變數名稱 in range(重複次數)
(tab) 想重複執行的動作
(tab) 想重複執行的動作
[root@localhost ~]# python
Python 2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> for count in range(3):
... print('repeat run')
... print(count)
...
repeat run
0
repeat run
1
repeat run
2
>>>
>>> for chara in word:
... print(chara)
...
n
i
n
j
a
沒有留言:
張貼留言