【发布时间】:2019-04-22 14:06:03
【问题描述】:
我正在循环一个布尔值列表
我的条件是元素的位置是否 > m
和if the element = True
函数会返回元素的位置
这就是我所做的:
panda =[True, True, True, True]
def find_next (l, m):
for i in l:
if ((l.index(i) > m) and i ==True):
return l.index(i)
print(find_next(panda, 2))
我预计输出为 3。
但我得到了None。为什么?
【问题讨论】:
-
欢迎来到 Stack Overflow。该代码将生成一个
IndentationError。请edit您的问题并解决它。我们不能指望猜测哪些错误是相关的,哪些不相关。最简单的做法是粘贴您的代码,然后选择它并单击{}按钮或按 Ctrl+K。