python3xiaobaike_2020/chapter2/2-14 python3小白课:身份运算符.md
2025-04-20 23:22:14 +08:00

34 lines
1.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# python3小白课身份运算符
身份运算符是用来表示身份的在python中用来比较对象是否相等。返回的结果也是True或者False。
来看例子:
```python
# coding:utf-8
a = 10
b = 5
# 判断对象是否相等常用场景是判断类型用is关键字
print(type(a) is int)
# 判断对象是否不相等常用场景也是判断类型判断是否是None的比较多用is not关键字
"""
None表示空值它是一个特殊 Python 对象, None的类型是NoneType
None不支持任何运算也没有任何内建方法
可以给变量赋值为None念的时候一般称作空值或空其他语言也有类似概念
做一些编程判断的很有用的一种类型比如没返回任何结果可以返回None等
***必须必须要知道它~***
"""
print(type(a) is not None)
c = None
print(c is None)
```
### 单词释义
| 单词 | 释义 |
| ------ | ------------------------------------------------------------ |
| None | python中的空值类型类型名为NoneType使用type(None)可以看到 |
| is | 是 |
| is not | is的否定形式表示不是 |