文書の表示以前のリビジョンバックリンク文書の先頭へ この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。 ====== for range enumerate 文 ====== ===== range 関数による繰り返し ===== <code python> In : range(5) Out: [0, 1, 2, 3, 4] for index in range(5): print('index: {0}'.format(index)) index: 0 index: 1 index: 2 index: 3 index: 4 </code> ===== enumerate 関数によるリストの繰り返し ===== <code python> In : colors = ['red', 'blue', 'green', 'pink', 'white'] for index, color in enumerate(colors): print('color{0}: {1}'.format(index, color)) color0: red color1: blue color2: green color3: pink color4: white </code> ===== continue と break ===== 一定の条件で処理をスキップ <code python> for index in range(10): if index >= 2 and index <= 7: continue print('index: {0}'.format(index)) index: 0 index: 1 index: 8 index: 9 </code> 一定の条件で処理を中止 <code python> for index in range(10): if index >= 4: break print('index: {0}'.format(index)) index: 0 index: 1 index: 2 index: 3 </code> python/for_range_enumerate.txt 最終更新: 2019/08/19 06:52by ともやん