这个&"if&"是什么意思?声明是什么意思? [英] What does this "if" statement mean?

查看:68
本文介绍了这个&"if&"是什么意思?声明是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个示例Hadoop reduce程序中,存在这样的"if"语句.我想知道什么时候相同的变量"a"在"if"语句中两次使用,如下所示:

 如果a和a == b:打印正在运行!" 

解决方案

仅当 a 为真时,才会测试是否相等( a == b ).

可以改写为

 如果是:如果a == b:print(正在工作!") 

请注意运算符的优先级: 等于 if(a and a)== b .

In an example Hadoop reduce program, such an "if" statement exists. I am wondering what it means when the same variable "a" is used twice in the "if" statement, as follows

if a and a == b:
    print "It is working!"

解决方案

It will test for equality (a == b) only if a is truthy.

It can be rewritten as

if a:
    if a == b:
        print("It is working!")

Note the operator precedence: it's not equal to if (a and a) == b.

这篇关于这个&"if&"是什么意思?声明是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆