Increment Operator in Python because ++ operator does not work in Python

This Python tutorial will be helpful for the curious Python learners. If you are familiar with other programming languages before Python then you must know that most of the programming languages have a ++ operator. Here we gonna learn what can we use instead of ++ operator in Python. Increment operator in Python is not the same as the other programming languages.

First of all, I would like to say that ++ is not an operator. In most of the programming languages ++ is used to increment the value of a variable by 1.

But the same thing you can achieve in Python in different ways. In this tutorial, I will show you how to achieve this.

Increment operator in Python

To be honest, most of the beginners ( Who done other programming languages before Python ) will be curious to know why Python does not deal with ++

The answer is simple. Just think of it: do you really need ++ in Python?

In most of the programming languages, the for loop looks like this:

for(i=0;i<5;i++){
// your code goes here
}

But think you are willing to do the same in Python. Your code will be like this:

for i in range(5):
  print(i)

Python provides us range() and this is enough to avoid ++



Even you can increment by using +=

a=5
a += 1

Actually, this is not an increment operator. This is nothing but a reassigning the value of a variable.

We can do actually the same thing as ++ in Python with += then why we will go for the extra load with another operator?

When you are getting all the work done you want to do in Python then why do you need another Syntax for the same?

I hope this was helpful to you. Feel free to comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *