双条件,浮点vs整数值

2024-04-19 22:12:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我有点疯了。我不明白这笔交易。你知道吗

这样做有效:

a=5
if a>2 & a<7: 
    print('Good')

这也适用于:

a=5.
if a>2: 
    print('Good')

但这行不通。你知道吗

a=5.
if a>2 & a<7: 
    print('Good')

我得到一个错误,告诉我它不支持浮动值。你知道吗

TypeError   Traceback (most recent call last)
<ipython-input-550-e437dc6fe8a9> in <module>()
      1 a=5.
----> 2 if a>2 & a<7:
      3     print('Good')

TypeError: unsupported operand type(s) for &: 'int' and 'float'

怎么回事?错误消息并没有真正告诉我如何处理浮动值,这就是我的数据库中的内容。看起来&是有问题的,因为一个条件可以处理浮点值。你知道吗


Tags: inmostinputif错误ipython交易call