如何测试x是否为通用集的成员? [英] How to test whether x is a member of a universal set?
本文介绍了如何测试x是否为通用集的成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列表L,如果x是L的成员,则x in L
的结果为True.我可以使用什么代替L,以便x in smth
单独取决于x的值而得出True?
I have a list L, and x in L
evaluates to True if x is a member of L. What can I use instead of L in order x in smth
will evaluate to True independently on the value of x?
所以,我需要包含所有对象(包括自身)的东西,因为x也可以是这个"smth".
So, I need something, what contains all objects, including itself, because x can also be this "smth".
推荐答案
class Universe:
def __contains__(_,x): return True
这篇关于如何测试x是否为通用集的成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文