简体   繁体   English

在python返回后再次开始循环

[英]start again for loop after return in python

For loop stops after return. For循环在返回后停止。 How to make it loop again? 如何使其再次循环? n = len(series) I need to return n separated lists with one integer in. n = len(series)我需要返回n个带一个整数的分离列表。

def _repeats(self, exercises, series):
    repeats = []
    for x in range(len(series)):
        repeats.append([])
    series_counter = 1
    for ex in exercises:
        n2 = 1
        print(series[series_counter - 1])
        print(type(series[series_counter - 1]))
        for serie in range(0, int(series[series_counter - 1])):
            x = int(input(
            "Number of repeats in {} serie {} : ".format(ex, n2)
                         ))
            repeats[n2 - 1].append(x)
            n2 += 1
            return repeats[n2 - 2]
        series_counter += 1

I advise you to study Python's Control Flow topic. 我建议您学习Python的Control Flow主题。 Including break and continue. 包括中断并继续。 Also, read about generators and yield command. 另外,请阅读有关生成器和yield命令的信息。

Best of luck. 祝你好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM