Python’s Fake Increment and Decrement Operators

HK Infosoft
1 min readAug 7, 2018

Content Source: Python Web Development

In Python, you can increase the value of a variable by 1 or reduce it by 1 using the augmented assignment operators. The code spam += 1 and spam -= 1 increments and decrements the numeric values in spam by 1, respectively.

Other languages such as C++ and Java have the ++ and — operators for incrementing and decrementing variables. (The name of C++ itself reflects this; the name is a tongue-in-cheek joke that indicates it’s an enhanced form of the C language.) Code in C++ and Java could have ++spam or spam++. Python wisely doesn’t include these operators; they are notoriously susceptible to subtle bugs.

Reading more

--

--

HK Infosoft

HK Infosoft has developed custom IT solutions for major companies in the USA, Canada, Europe and Australia for many years, igniting and developing their ideas..