如何在 Python 的函数中包含"if"和"for"循环?



我正在尝试编写一个类似这样的函数。

def function(statement):
if statement:
for loop
else: 
continue
...
function(statement = True)

然后,函数(statement=True(应该运行for循环。例如,如果语句为false,它将继续执行函数的其余部分。它目前还不起作用,所以我们非常感谢您对如何实现这一点的任何帮助。

以下是我上面的建议(您需要拼写出循环(:

def function(statement):
if statement:
for x in y:
...

最新更新