使用break语句退出循环[关闭]

问题描述 投票:-1回答:1
我想检测程序何时看到值26,我有一个看起来像这样的函数

val = 26 for n in range (0,101): if n in val: print(n,"is the value i am looking for") break else: print(n)

我一直收到此错误:

TypeError: argument of type 'int' is not iterable

此功能有什么问题
python
1个回答
1
投票
n in val检查值n是否在可迭代的val中。此处正确的检查是n == val
© www.soinside.com 2019 - 2024. All rights reserved.