Py学习  »  Python

如何在Python中缩写这个条件?[重复]

4daJKong • 3 年前 • 1128 次点击  

我有这样的情况:

str1 = "cat, dog, rat"
print( ("cat" not in str1) and ("dog" not in str1) and ("rat" not in str1)) #1
print(any(x not in str1 for x in ("cat","dog","rat"))) #2

问题是,如果我添加任何其他语句,那么#1条件太长,所以我将其转换为#2,但是#2返回相反的结果,那么如何简单地用Python编写#1呢?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/132483
 
1128 次点击  
文章 [ 2 ]  |  最新文章 3 年前