Python integer incrementing with ++

Possible Duplicate:
Python: Behaviour of increment and decrement operators

I've always laughed to myself when I've looked back at my VB6 days and thought, "What modern language doesn't allow incrementing with double plus signs?":

number++

To my surprise, I can't find anything about this in the Python docs. Must I really subject myself to number = number + 1 ? Don't people use the ++/-- notation?


Python不支持++ ,但你可以这样做:

number += 1

Simply put, the ++ and -- operators don't exist in Python because they wouldn't be operators, they would have to be statements. All namespace modification in Python is a statement, for simplicity and consistency. That's one of the design decisions. And because integers are immutable, the only way to 'change' a variable is by reassigning it.

Fortunately we have wonderful tools for the use-cases of ++ and -- in other languages, like enumerate() and itertools.count() .


你可以做:

number += 1
链接地址: http://www.djcxy.com/p/40236.html

上一篇: 检查三个布尔中至少有两个是否为真

下一篇: 用++来增加Python整数