「Python」for文でネスト多階層の繰り返し処理をするサンプル

2021年4月7日

書式
for 変数名A in range(数値):
for 変数名B in range(数値):
使用例

# coding: utf-8

for m in range(4):

        for n in range(4):
                if n == 0:
                        continue
                print("n value is " + str(n))

        print("m value is " + str(m))

結果
# python 2.py
n value is 1
n value is 2
n value is 3
m value is 0
n value is 1
n value is 2
n value is 3
m value is 1
n value is 1
n value is 2
n value is 3
m value is 2
n value is 1
n value is 2
n value is 3
m value is 3

Python

Posted by arkgame