+ 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

21st Jan 2018, 11:19 AM
rdhelli
rdhelli - avatar
2 ответов
+ 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
21st Jan 2018, 11:59 AM
michal
+ 1
thanks, makes sense
21st Jan 2018, 12:03 PM
rdhelli
rdhelli - avatar