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 below and syntax is as follow:
for variable_name in range(start, stop, step)
- start: Optional. An integer number specifying at which position to start. Default is 0
- stop: An integer number specifying at which position to end.
- step: Optional. An integer number specifying the incrementation. Default is 1
Output-1: INCREMENTED FOR LOOP 0 1 2 3 4 Output-2: DECREMENTED FOR LOOP 4 3 2 1 0
This article is contributed by Basavaraja. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Division Operators in Python
- What are the operators that can be and cannot be overloaded in C++?
- new and delete operators in C++ for dynamic memory
- Case conversion (Lower to Upper and Vice Versa) of a string using BitWise operators in C/C++
- Basic Operators in Java
- Operators in Java
- Operators in C / C++
- Written version of Logical operators in C++
- Largest of two distinct numbers without using any conditional statements or operators
- Check if a Number is Odd or Even using Bitwise Operators
- Generate first K multiples of N using Bitwise operators
- Loops and Control Statements (continue, break and pass) in Python
- Python | Set 4 (Dictionary, Keywords in Python)
- Python List Comprehension and Slicing
- Object Oriented Programming in Python | Set 1 (Class, Object and Members)
- Object Oriented Programming in Python | Set 2 (Data Hiding and Object Printing)
- Global and Local Variables in Python
- Counters in Python | Set 1 (Initialization and Updation)
- OOP in Python | Set 3 (Inheritance, examples of object, issubclass and super)
- Mathematical Functions in Python | Set 2 (Logarithmic and Power Functions)
Improved By : Basavaraja