
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Increment and Decrement Operators
In this article, we will learn about increment and decrement operators in Python 3.x. Or earlier. In other languages we have pre and post increment and decrement (++ --) operators.
In Python we don’t have any such operators . But we can implement these operators in the form as dicussed in example below.
Example
x=786 x=x+1 print(x) x+=1 print(x) x=x-1 print(x) x-=1 print(x)
Output
787 788 787 786
Other languages have for loops which uses increment and decrement operators. Python offers for loop which has a range function having default increment value “1” set. We can also specify our increment count as a third argument in the range function
Example
for i in range(0,5): print(i) for i in range(0,5,2): print(i)
Output
0 1 2 3 4 0 2 4
Conclusion
In this article, we learned how to use Increment and Decrement Operators in Python.
- Related Articles
- Increment and Decrement Operators in Python?
- PHP Increment/Decrement Operators
- Increment and decrement operators in Java
- Increment ++ and decrement -- Operators in C++
- Increment and Decrement Operators in C#
- Why avoid increment (“++”) and decrement (“--”) operators in JavaScript?
- What are increment (++) and decrement (--) operators in C#?
- Interesting facts about Increment and Decrement operators in Java
- What are the restrictions on increment and decrement operators in java?
- Increment ++ and Decrement -- Operator Overloading in C++
- Pre-increment (or pre-decrement) in C
- Write a C program to demonstrate post increment and pre increment operators
- Increment Negative and Decrement Positive Numbers by 1 in an Array in Java
- Count of suffix increment/decrement operations to construct a given array in C++
- Create increment decrement plus minus buttons programmatically for HTML input type number in JavaScript

Advertisements