Python Increment and Decrement by 1

When I first started coding in Python more than a decade ago, I often wondered why there wasn’t a built-in increment (++) or decrement (–) operator like in C or Java.

If you’re new to Python, this can feel confusing at first. But don’t worry: Python makes this process simple and flexible with its own style.

In this tutorial, I’ll show you step-by-step how to increment and decrement values by 1 in Python. I’ll also share real-world examples from my projects in the USA, where I’ve used these techniques in loops, counters, and even data analysis tasks.

Python Increment By 1

Python Increments by 1 means increasing the value by a specific amount. In other programming languages like C, C++, etc., the operator ‘++’ is used to increment the value by a certain amount, but in Python, there is no ‘++’ operator to increment the value by a certain amount.

Increment Operator in Python

However, in Python, there is a way to increment the value by a specific amount; that way is using the ‘+=’ operator.

The syntax is given below.

variable +=increment_value

Where,

  • variable +=increment_value: This means increasing the variable value by increment_value.

For example, suppose you are creating a program to count the number of attendees entering an event. Initially, the variable count will have a value of zero.

But as soon as attendees enter the event, the value of the count variable must increase by one for each attendee, and you can do that using the ‘+=’ operator, as shown below.

attendee_count = 0
attendee_count+=1

print('Attendee count', attendee_count)

You can see the output in the screenshot below.

Increment Operator in Python

If you again call attendee_count+=1, the variable attendee_count becomes 2 as the value increases by one. This is how you can use the Python increment operator ‘+=’ to increment the variable by 1.

Check out Find the Maximum Value in Python Using the max() Function

Increment and Decrement Operators in Python

In the preceding section, you learned about the increment operation ‘+=’: there is also a decrement operator, which is ‘-=’, that decreases the value by a specific amount.

The syntax is given below.

variable -=decrement_value

Where,

  • variable -=decrement_value: It means decreasing the variable value by decrement_value.

Again, let’s take the same attendees’ example, but this time, when attendees leave the event, the variable attendee_count value decreases by 1.

For example, if 50 attendees are present at the event, the value of attendee_count is 50, as shown below.

attendee_count = 50

Now, one attendee leaves the event, so the value of attendee_count must decrease, which can be done using the ‘-=’ operator, as shown below.

attendee_count -=1
print('Attendee count', attendee_count)

You can see the output in the screenshot below.

Increment Operator in Python

This is how you can use the Python decrement operator ‘-=’ to decrement the variable by 1.

Difference Between Increment and Decrement Operators in Python

Let me explain to you the difference between Python increment and decrement operators.

AspectIncrement Operator in PythonDecrement Operator in Python
Operators UsedWe use ‘+=’ or ‘+’ operators as increment operator in PythonWe use ‘-=’ or ‘-‘ operators as decrement operator in Python
EffectsIncreases the variable by a specified value.Decreases the variable by a specified value.
Syntax‘x += 1’ or ‘x = x + 1’‘y -= 1’ or ‘y = y – 1’
UsageTypically used in loops, counters, or variable updates.Can we use two strings in Python, but with str and numbers?
Can we use two strings in Python but with str and numbers?Throw ValueError cannot be used with two strings in Python or a string with numbers.
List of differences between increment and decrement operators in Python. I hope you understand how to increment and decrement the variable value by 1 using the ‘+=’ and ‘-=’ operators.

Conclusion

In this Python tutorial, you learned about Python increment by 1 with syntax and examples.

You also learned about the decrement operator ‘-=’ to decrease the variable value by a certain amount. Additionally, you knew the difference between increment and decrement operators in Python.

You may like to read:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.