Python大一内容谁可以解释一下

img


为什么运算结果不是 布尔类型

print(a) 返回值为None
所以执行的是None and 'a=T' or 'a=F' 这个式子先算None and 'a=T',其结果为None
最后算None or 'a=F' 所以结果为'a=F'

看懂以下结论,就知道为什么了

```python

bool(None)
False
bool('a=F')
True
bool(None)
False
bool('a=T')
True
None and 'a=T'
0 and 'a=T'
0
1 and 'a=T'
'a=T'
None or 'a=T'
'a=T'
0 or 'a=T'
'a=T'
1 or 'a=T'
1
None and 1 or 'a=F'
'a=F'
1 and 1 or 'a=F'
1
```

=是赋值,==才会是布尔

img


实践出真知,有帮助的话请采纳,谢谢!!!

为什么运算结果不是 布尔类型?
因为=是赋值运算符 ==是比较运算符
比较会有对错 即True or False之分

望采纳!!