Increment & decrement operators [python] | Sololearn: Learn to code for FREE!

+2

Increment & decrement operators [python]

Okay so I've read that in python, the operators '++', '--' etc. are not implemented (like in c++). I also get the reason behind: they are not needed as often, thanks to iteration with range(8), and so on. But then what exactly happens when someone does use them? After testing: c = 0 c = ++c # seemingly nothing changes c = c++ # throws syntax error

1/21/2018 11:19:41 AM

rdhelli

3 Answers

New Answer

+2

you cannot use this operators, because they are not implemented when you do c=++c, it is something like c= -c. The second changes the sign of the number. When you use + instead of -, it doesn't change the sign. ++c is the same operation applied twice, so c=++c is the same as c=c

+2

x+=1 should work for you

+1

thanks, makes sense