Reg*_*ser 1 python java boolean transform
我在python中有以下表达式:
if 0.85 < 0.81 / 0.83 < 1.15 :
//do something
Run Code Online (Sandbox Code Playgroud)
当我把它放在python中没有问题,它返回一个布尔值(true),但我不明白'/'是什么?因为它看起来像你分开两个布尔.这个表达式在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
}
Run Code Online (Sandbox Code Playgroud)
在Python中,所有比较操作都具有相同的优先级.它可以任意链接,例如,x < y < z相当于x < y and y < z.有关详细说明,请参阅Python文档:表达式.