Error in user YAML: (<unknown>): found a tab character that violate indentation while scanning a plain scalar at line 3 column 3
---
- oeasy Python 0149
- 这是 oeasy 系统化 Python 教程,从基础一步步讲,扎实、完整、不跳步。愿意花时间学,就能真正学会。
- 本教程同步发布在:
- 个人网站: `https://oeasy.org`
- 蓝桥云课: `https://www.lanqiao.cn/courses/3584`
- GitHub: `https://github.com/overmind1980/oeasy-python-tutorial`
- Gitee: `https://gitee.com/overmind1980/oeasypython`
---- 这次研究了 in
- 成员测试 运算符
- Membership test operations
| 判断 | 结果 |
|---|---|
| 在容器里 | True |
| 不在容器里 | False |
- in 和 not in 都是
- 成员测试运算符
- 这个 not in 是什么意思呢??🤔
- not 就是否定
- 对 真值 反转
- inverse true value
- True 变 False
- False 变 True
- 动手试试
1 in [0, 1]
1 not in [0, 1]
- 原来是 True
- 反转 就是 False 了
- 能给 True /False
- 直接加not吗?
- 不真就是假
- 不假就是真
not True
not False
- 真假 可以通过 not
- 反转
- inverse
- 反转 再 反转 会发生什么?
not not True
not not False
- not not True
- 其实就是True
-
取反再取反
- 就会回到原点
-
否定之否定
- 就是肯定
- 负负为正
- 比较运算的结果
- 可以 再not 吗?
2 > 1
not 2 > 1
1 in [1]
not 1 in [1]
- 先 比较 得到 真值
- 再 反转
- 可以改成
- 不带not的吗?
- 进入帮助
help()
COMPARISON
- 这应该如何理解
- 下面的命题等价
- 等于 就不是 不等于
- 小于 就是 不大于等于
- 大于 就是 不小于等于
- 动手试试
- 这里的 not {1} >= {1, 2}
- 相当于 not ({1} >= {1, 2})
- 相当于 not False
- 结果为True
- 比较运算符
- 还有个is
- 身份比较
- Identity comparision
- is 身份比较
- 比的是 identity
- 什么 是 identity?
- 这个我们见过
help(id)
- id 可以看
- 内存地址
- 具体试试
lst1 = [0]
lst2 = [0]
lst1 == lst2
lst1 is lst2
- 两个列表 相等
- 但指向 不同地址
- 想让 is 也是 True
- 使用lst1 给lst2赋值
lst1 = [0]
lst2 = lst1
lst1 == lst2
lst1 is lst2- 此时两个变量
- 指向同一地址
- 返回结果为True
- https://pythontutor.com/visualize.html#mode=edit
- 想要 赋值 也不等
- 怎么办?
lst1 = [0]
lst2 = lst1.copy()
lst1 == lst2
lst1 is lst2- 浅拷贝 就可以完成
- is 的 not
- 该 放到 哪?
- not
- 可以加在 最前面
- 也可以 加在is 后面
lst1 is lst2
not lst1 is lst2
lst1 is not lst2
- is not
- 说起来 也合理
- 不是
- 这次研究了 is
- 身份比较
- Identity comparision
- 看的是 变量 是否 相同
| 关键词 | 含义 |
|---|---|
| in | 是否在容器里 |
| is | 是否是同一个对象 |
- not
- not 就是取反
- True 变 False
- False 变 True
- 如果 我想对 比较结果
分别处理- 该怎么办呢???🤔
- 下次再说 👋
- 本文来自 oeasy Python 系统教程。
- 想完整、扎实学 Python,
- 搜索 oeasy 即可。

















