20-浮点 NaN 的 bool 值

20-浮点 NaN 的 bool 值

语法讲解 今天学: NaN 的真值测试 x = float("nan") print(bool(x)) 小练习 运行下面代码后输出是什么? x = float("

阅读更多 →
19-非零浮点转 int 再 bool:信息丢失

19-非零浮点转 int 再 bool:信息丢失

语法讲解 今天学: float -> int -> bool 的风险 x = 0.9 print(bool(int(x))) 小练习 运行下面代码后输出是什么? x = 0.9 p

阅读更多 →
18-输入题:'False' 用 bool(s) 会怎样

18-输入题:'False' 用 bool(s) 会怎样

语法讲解 今天学: 字符串直接 bool() 的陷阱 s = input().strip() print(bool(s)) 小练习 输入为:False。运行下面代码后输出是什么? s = in

阅读更多 →
17-输入题:'0' 和 '1' 转 bool(正确方式)

17-输入题:'0' 和 '1' 转 bool(正确方式)

语法讲解 今天学: 把 '0'/'1' 转为布尔 s = input().strip() print(bool(int(s))) 小练习 输入为:0。运行下面代

阅读更多 →
16-bool 与位运算:& 与 and 的区别

16-bool 与位运算:& 与 and 的区别

语法讲解 今天学: & 与 and print(True & False) print(True and False) 小练习 运行下面代码后输出是什么?(多行输出请按真实换行

阅读更多 →
15-and 也返回操作数本身

15-and 也返回操作数本身

语法讲解 今天学: and 的返回值规则 print(0 and 5) print(2 and 5) 小练习 运行下面代码后输出是什么?(多行输出请按真实换行提交) print(0 and 5

阅读更多 →
14-or 返回的不是 bool(返回操作数本身)

14-or 返回的不是 bool(返回操作数本身)

语法讲解 今天学: or 的返回值规则 print(0 or 2) print(0 or 0) 小练习 运行下面代码后输出是什么?(多行输出请按真实换行提交) print(0 or 2) pr

阅读更多 →
13-bool(list/tuple/dict):空为 False

13-bool(list/tuple/dict):空为 False

语法讲解 今天学: 容器的真值测试 print(bool([])) print(bool([0])) print(bool({})) print(bool({"a": 0}))

阅读更多 →
12-float(True/False)

12-float(True/False)

语法讲解 今天学: bool 转 float print(float(True)) print(float(False)) 小练习 运行下面代码后输出是什么?(多行输出请按真实换行提交) pr

阅读更多 →
11-True is 1 吗?(身份 vs 相等)

11-True is 1 吗?(身份 vs 相等)

语法讲解 今天学: is 与 == print(True is 1) print(True == 1) 小练习 运行下面代码后输出是什么?(多行输出请按真实换行提交) print(True i

阅读更多 →