官术网_书友最值得收藏!

Testing for equality of identity with is

In reality, the id() function is seldom used in production Python code. Its main use is in object model tutorials (such as this one!) and as a debugging tool. Much more commonly used than the id() function is the is operator which tests for equality of identity. That is, is tests whether two references refer to the same object:

>>> a is b
True

We've already met the is operator earlier, in Chapter 1, Getting started, when we tested for None:

>>> a is None
False

It's critical to remember that is is always testing identity equality, that is, whether two references refer to the exact same object. We'll look in-depth at the other primary type of equality, value equality, in just a bit.

主站蜘蛛池模板: 枣强县| 高陵县| 图木舒克市| 杭锦后旗| 喜德县| 鄂伦春自治旗| 澳门| 宝山区| 汪清县| 青海省| 南岸区| 普陀区| 邓州市| 仙桃市| 友谊县| 海口市| 湟源县| 子长县| 白城市| 射阳县| 永新县| 新干县| 临邑县| 舞钢市| 方城县| 常熟市| 双城市| 尚义县| 乐亭县| 广元市| 嘉祥县| 五峰| 米脂县| 长兴县| 班玛县| 霞浦县| 马山县| 铁岭市| 喜德县| 玛沁县| 专栏|