> For the complete documentation index, see [llms.txt](https://lujw666.gitbook.io/learn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lujw666.gitbook.io/learn/python/00-basic/00-yun-suan-fu/07-shen-fen-yun-suan-fu.md).

# 身份运算符

身份运算符用于比较两个对象的存储单元

| 运算符    | 描述                        | 实例                                               |
| ------ | ------------------------- | ------------------------------------------------ |
| is     | is 是判断两个标识符是不是引用自一个对象     | x is y, 如果 id(x) 等于 id(y) , is 返回结果 Ture         |
| is not | is not 是判断两个标识符是不是引用自不同对象 | x is not y, 如果 id(x) 不等于 id(y). is not 返回结果 Ture |

```python
a = 20
b = 20

if ( a is b ):
   print ("1 - a 和 b 有相同的标识")
else:
   print ("1 - a 和 b 没有相同的标识")

if ( id(a) == id(b) ):
   print ("2 - a 和 b 有相同的标识")
else:
   print ("2 - a 和 b 没有相同的标识")

# 修改变量 b 的值
b = 30
if ( a is b ):
   print ("3 - a 和 b 有相同的标识")
else:
   print ("3 - a 和 b 没有相同的标识")

if ( a is not b ):
   print ("4 - a 和 b 没有相同的标识")
else:
   print ("4 - a 和 b 有相同的标识")
```

[demo](https://github.com/lujw666/learn/blob/develop/python/00-basic/04-arithmetic/07-身份运算符.py)

[返回](/learn/python/00-basic/00-yun-suan-fu.md)
