简体   繁体   English

在Python中具有加号,等于号和大于号的表达式

[英]Expression with plus, equal, and greater than symbols in python

I understand that an expression like i += 1 usually means i = i+1 ... 我了解类似i += 1的表达式通常意味着i = i+1 ...

What would the operation below mean? 以下操作意味着什么?

b += c > 0

In general, x op = expression , is the syntax for shorthand operators . 通常, x op = expression是速记operators的语法。 It will be evaluated like x = x op expression. 它将像x = x op表达式那样求值。

As said above in comments, "b += True will increment b by 1 and b += False will not change the value of b", It will see if c is bigger than 0, or not. 如上面的注释中所述,“ b + = True将使b增加1,而b + = False将不会改变b的值”,它将查看c是否大于0。 if it is it will increment b by 1 如果是,它将b增加1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM