python:类覆盖“is"行为 [英] python: class override "is" behavior

查看:43
本文介绍了python:类覆盖“is"行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个封装任意对象的类,包括简单类型.我想让is"关键字对封装的值进行操作,比如这个行为:

I'm writing a class which encapsulates any arbitrary object, including simple types. I want the "is" keyword to operate on the encapsulated value, such as this behavior:

Wrapper(True) is True -> True
Wrapper(False) is True -> False
Wrapper(None) is None -> True
Wrapper(1) is 1 -> True

有没有我可以重写的对象方法来获得这种行为?

Is there any object method I can override to get this behavior?

推荐答案

没有.isandor 不能重载.

No. is, and, and or cannot be overloaded.

这篇关于python:类覆盖“is"行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆