您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在Python中实现list类的__contains__方法?

如何在Python中实现list类的__contains__方法?

不,它们不相等。例如:

>>> mode = float('nan')
>>> allowed_modes = [mode]
>>> any(mode == allowed_mode for allowed_mode in allowed_modes)
False
>>> mode in allowed_modes
True

有关更多详细信息,请参阅成员资格测试操作包括以下语句:

对于list,tuple,set,frozenset,dict或collections.deque等容器类型,该表达式x in y等效于any(x is e or x == e for e in y)

python 2022/1/1 18:25:03 有166人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶