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:
>>> a = 1
>>> ++a
1
>>> print a
1
>>> print(++a)
1
Could somebody explain this? If Python support ++, why num has not changed. If it doesn't why can I use ++?
Python list can contain duplicate elements. Let's look into examples of removing the duplicate elements in different ways.
Tuple is a collection which is ordered and unchangeable. Allows duplicate members.
The Key value of a Dictionary is unique and doesn't let you add a duplicate key entry.
Set by definition is unordered collections of unique elements, so they don't allow duplicates.
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
It should look like
a = 6
a += 1
print a
>>> 7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With