简体   繁体   中英

Expression with plus, equal, and greater than symbols in python

I understand that an expression like i += 1 usually means i = i+1 ...

What would the operation below mean?

b += c > 0

In general, x op = expression , is the syntax for shorthand operators . It will be evaluated like x = x op expression.

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. if it is it will increment b by 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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