只是检查一下,我找不到关于~,所以我想确定它是一样的。
还有,你能用吗!在Python中,像C++一样?
这两个代码似乎给出了相同的输出:
bool(~0)
bool(not 0)
你应该读 Python 3.10 documentation 在 Unary arithmetic and bitwise operations .
Python 3.10 documentation
Unary arithmetic and bitwise operations
这个 ~ 操作员的工作很简单:
~
反转位
Python就是这样的。
“~”是位运算符 而“not”是一个逻辑运算符
“~”是位运算符
而“not”是一个逻辑运算符