Python3-identity-operators-example
提供:Dev Guides
Python 3-アイデンティティ演算子の例
Python組み込み関数id()は、オブジェクトのIDとして一意の整数を返します。 アイデンティティ演算子は、2つのオブジェクトのメモリ位置を比較します。 以下に説明するように、2つのアイデンティティ演算子があります-
Operator | Description | Example |
---|---|---|
is | Evaluates to true if the variables on either side of the operator point to the same object and false otherwise. | x is y, here *is *results in 1 if id(x) equals id(y). |
is not | Evaluates to false if the variables on either side of the operator point to the same object and true otherwise. | x is not y, here* is not* results in 1 if id(x) is not equal to id(y). |
例
出力
上記のプログラムを実行すると、次の結果が生成されます-