我在 python 中有以下表达式:
if 0.85 < 0.81 / 0.83 < 1.15 :
//do something
当我把它放在 python 中时没有问题,它返回一个 boolean 值 (true) 但我不明白“/”是什么?因为它看起来像你除以两个 boolean 值。这个表达式在 Java 中的作用是什么?
请您参考如下方法:
在Java中,
if (0.85 < 0.81 / 0.83 && 0.81 / 0.83 < 1.15) {
//do something
}
// A better solution as mentioned by @Makoto
float f = 0.81/0.83
if (0.85<f && f< 1.15) {
//do something
}
在 Python 中,所有的比较操作都具有相同的优先级。它可以任意链接,例如 x < y < z相当于x < y and y < z .引用Python documentation: Expressions详细说明。
