我举了一个这样的例子:
identified_characters = ["a","c","f","h","l","o"]
word = "alcachofa#"
if any(character in word for character not in identified_characters):
print("there are unidentified characters inside the word")
else:
print("there aren't unidentified characters inside the word")
但是not
带来了语法错误,所以我想如果有一个out
(我猜是in
的相反)函数,理论上你可以更改not in
并保留语法
我还认为给定结果的逻辑应该是any
函数的对立面,但我向上看时发现,ppl的对立面应该是not all
,在这种情况下,在这里不起作用
您不能循环使用不在
identified_characters
中的所有可能项目;莫名其妙地有很多。这在概念上甚至没有意义要实现您想要的(检查
word
中是否有未识别的字符(不在identified_characters
中的字符),您必须循环word
,而不是identified_characters
的补码不要在
for
语句中使用not
,而是在character in word
部分使用它For循环可以使用
in
,但不能使用not in
,因为它们不知道not in
的意思!For循环用于遍历列表或任何iterable,不能遍历iterable中不存在的内容,因为它们不知道什么不在iterable中。您还可以通过以下方式使用not all
:相关问题 更多 >
编程相关推荐