Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 解决了为什么不';是否执行了两个连续的for循环?_Python_Order Of Execution_Nested For Loop - Fatal编程技术网

Python 解决了为什么不';是否执行了两个连续的for循环?

Python 解决了为什么不';是否执行了两个连续的for循环?,python,order-of-execution,nested-for-loop,Python,Order Of Execution,Nested For Loop,[初学者提示]我正在编写代码并记录它们的变化。我想将这个for循环的变体合并到一个文件中,但只执行第一个文件。为了实现这一目标,我必须做什么 teams = ['Dragons', 'Wolves', 'Pandas', 'Unicorns'] n = 1 for home_team in teams: for away_team in teams[n:]: # This block causes the execution to increase n by one

[初学者提示]我正在编写代码并记录它们的变化。我想将这个for循环的变体合并到一个文件中,但只执行第一个文件。为了实现这一目标,我必须做什么

teams = ['Dragons', 'Wolves', 'Pandas', 'Unicorns']
n = 1

for home_team in teams:
    for away_team in teams[n:]:     # This block causes the execution to increase n by one
        if home_team != away_team:  # for every away_team in one home_team
            print(home_team, away_team)  # then proceeds to the next home_team
            n += 1

for home_team in teams:
    for away_team in teams[n:]:     # This block causes the execution to increase n by one
        if home_team != away_team:  # for every home_team
            print(home_team, away_team)
    n += 1

第二部分假设n的值自第一部分结束后没有改变,导致执行没有打印任何结果。[马克·迈耶暗示]

当第二个循环开始时,
n
的值是多少?相同的值,我明白你的意思,谢谢!