Increment and Decrement Operators in Python
If you’re familiar with Python, you would have known Increment and Decrement operators ( both pre and post) are not allowed in it.
Python is designed to be consistent and readable. One common error by a novice programmer in languages with ++ and -- operators is mixing up the differences (both in precedence and in return value) between pre and post increment/decrement operators. Simple increment and decrement operators aren’t needed as much as in other languages.
You don’t write things like :
for (int i = 0; i < 5; ++i)
In Python, instead we write it like
# A Sample Python program to show loop (unlike many # other languages, it doesn't use ++) for i in range(0, 5): print(i) |
Output:
0 1 2 3 4
We can almost always avoid use of ++ and --. For example, x++ can be written as x += 1 and x-- can be written as x -= 1.
This article is contributed by Harshit Gupta. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Recommended Posts:
- Python | Increment value in dictionary
- Ways to increment a character in Python
- Python | Increment 1's in list based on pattern
- Division Operators in Python
- Python Bitwise Operators
- Basic Operators in Python
- Logical Operators on String in Python
- Inplace vs Standard Operators in Python
- Python Membership and Identity Operators | in, not in, is, is not
- Chaining comparison operators in Python
- Python | Splitting operators in String
- Python Logical Operators with Examples [Improvement needed]
- Inplace Operators in Python | Set 1 (iadd(), isub(), iconcat()...)
- Inplace Operators in Python | Set 2 (ixor(), iand(), ipow(),…)
- Python | Solve given list containing numbers and arithmetic operators

