is 和 == 操作符的區別
python官方解釋:
== 的meaning為equal;
is的meaning為object identity;
is 判斷對象是否相等,即身份是否相同,使用id值判斷;
== 判斷對象的值是否相等。
id值是什么?
id()函數官網解釋:
id(object)
Return the “identity” of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id()?value.
CPython implementation detail: This is the address of the object in memory.
返回對象的身份,即在對象生命周期中對象保證唯一不變的整數。不重疊的兩個對象可能會有同樣的id值。
對于CPython解釋器:id值是對象在內存中的地址。
?
Cpython是什么?
python解釋器用來執行.py文件。從python官網下載并安裝好Python后,我們就直接獲得了一個官方版本的解釋器:CPython。這個解釋器是用C語言開發的,所以叫CPython。在命令行下運行python就是啟動CPython解釋器。CPython是使用最廣的Python解釋器。
?