【发布时间】:2021-08-11 04:10:55
【问题描述】:
第一个代码给出 True,但第二个代码给出一个错误“TypeError: unsupported operand type(s) for &: 'str' and 'int'”。
Python中的“&”和“and”运算符有什么区别?不一样吗?
student = "Justin"
第一个代码
print(student == "Justin" and 1 == 1)
第二个代码
print(student == "Justin" & 1 == 1)
【问题讨论】:
-
and是布尔值,&是按位与,优先级更高