Skip to content Skip to sidebar Skip to footer

Does Python Support ++?

Possible Duplicate: Behaviour of increment and decrement operators in Python I'm new to Python, I'm confused about ++ python. I've tried to ++num but num's value is not changed:

Solution 1:

No:

In [1]: a=1

In [2]: a++
------------------------------------------------------------
   File "<ipython console>", line 1
     a++
        ^
SyntaxError: invalid syntax

But you can:

In [3]: a+=1

In [4]: a
Out[4]: 2

Solution 2:

It should look like

a = 6
a += 1
print a
>>> 7

Solution 3:

There should be one and preferably only one obvious way to do it

>>> a = 1
>>> a += 1
>>> a
2

Post a Comment for "Does Python Support ++?"