デヂ録

貧乏ブロガーの備忘録です。思った事やわかった事など気まぐれに書いています。

for文、while(ループ)

Pyhotnを使用したループ文

回数指定(for文)

count = 3
for index in range(count):  print(index)

 

配列の数だけ繰り返す(for文)

numbers = ['0','1','2','3','4']
for index in numbers:
 print(index)

 

回数指定(while文)

count = 3
while index < count:
  index += 1
  print(index)

 

2秒ごとにループ(while文)

import time
t_second = 2
while(True):
    #処理を記述
time.sleep(t_second)