- The Python Apprentice
- Robert Smallshire Austin Bingham
- 131字
- 2021-07-02 22:17:03
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.
推薦閱讀
- ClickHouse性能之巔:從架構設計解讀性能之謎
- Rust實戰
- Oracle Exadata專家手冊
- Yii Project Blueprints
- 細說Python編程:從入門到科學計算
- Spring 5 Design Patterns
- RESTful Web Clients:基于超媒體的可復用客戶端
- ASP.NET 4.0 Web程序設計
- 計算機應用基礎案例教程(第二版)
- ASP.NET Core and Angular 2
- Java程序設計入門(第2版)
- SQL Server 2014 Development Essentials
- ANSYS FLUENT 16.0超級學習手冊
- MATLAB計算機視覺實戰
- Python量子計算實踐:基于Qiskit和IBM Quantum Experience平臺