++ is not an operator. It is two + operators. The + operator is the identity operator, which does nothing. (Clarification: the + and - unary operators only work on numbers, but I presume that you wouldn't expect a hypothetical ++ operator to work on strings.)

++count

Parses as

+(+count)

Which translates to

count

You have to use the slightly longer += operator to do what you want to do:

count += 1

I suspect the ++ and -- operators were left out for consistency and simplicity. I don't know the exact argument Guido van Rossum gave for the decision, but I can imagine a few arguments:

  • Simpler parsing. Technically, parsing ++count is ambiguous, as it could be +, +, count (two unary + operators) just as easily as it could be ++, count (one unary ++ operator). It's not a significant syntactic ambiguity, but it does exist.
  • Simpler language. ++ is nothing more than a synonym for += 1. It was a shorthand invented because C compilers were stupid and didn't know how to optimize a += 1 into the inc instruction most computers have. In this day of optimizing compilers and bytecode interpreted languages, adding operators to a language to allow programmers to optimize their code is usually frowned upon, especially in a language like Python that is designed to be consistent and readable.
  • Confusing side-effects. One common newbie error in languages with ++ operators is mixing up the differences (both in precedence and in return value) between the pre- and post-increment/decrement operators, and Python likes to eliminate language "gotcha"-s. The precedence issues of pre-/post-increment in C are pretty hairy, and incredibly easy to mess up.
Answer from Chris Lutz on Stack Overflow
Top answer
1 of 11
1353

++ is not an operator. It is two + operators. The + operator is the identity operator, which does nothing. (Clarification: the + and - unary operators only work on numbers, but I presume that you wouldn't expect a hypothetical ++ operator to work on strings.)

++count

Parses as

+(+count)

Which translates to

count

You have to use the slightly longer += operator to do what you want to do:

count += 1

I suspect the ++ and -- operators were left out for consistency and simplicity. I don't know the exact argument Guido van Rossum gave for the decision, but I can imagine a few arguments:

  • Simpler parsing. Technically, parsing ++count is ambiguous, as it could be +, +, count (two unary + operators) just as easily as it could be ++, count (one unary ++ operator). It's not a significant syntactic ambiguity, but it does exist.
  • Simpler language. ++ is nothing more than a synonym for += 1. It was a shorthand invented because C compilers were stupid and didn't know how to optimize a += 1 into the inc instruction most computers have. In this day of optimizing compilers and bytecode interpreted languages, adding operators to a language to allow programmers to optimize their code is usually frowned upon, especially in a language like Python that is designed to be consistent and readable.
  • Confusing side-effects. One common newbie error in languages with ++ operators is mixing up the differences (both in precedence and in return value) between the pre- and post-increment/decrement operators, and Python likes to eliminate language "gotcha"-s. The precedence issues of pre-/post-increment in C are pretty hairy, and incredibly easy to mess up.
2 of 11
451

Python does not have pre and post increment operators.

In Python, integers are immutable. That is you can't change them. This is because the integer objects can be used under several names. Try this:

>>> b = 5
>>> a = 5
>>> id(a)
162334512
>>> id(b)
162334512
>>> a is b
True

a and b above are actually the same object. If you incremented a, you would also increment b. That's not what you want. So you have to reassign. Like this:

b = b + 1

Many C programmers who used python wanted an increment operator, but that operator would look like it incremented the object, while it actually reassigns it. Therefore the -= and += operators where added, to be shorter than the b = b + 1, while being clearer and more flexible than b++, so most people will increment with:

b += 1

Which will reassign b to b+1. That is not an increment operator, because it does not increment b, it reassigns it.

In short: Python behaves differently here, because it is not C, and is not a low level wrapper around machine code, but a high-level dynamic language, where increments don't make sense, and also are not as necessary as in C, where you use them every time you have a loop, for example.

🌐
GeeksforGeeks
geeksforgeeks.org › python › g-fact-21-increment-and-decrement-operators-in-python
Increment += and Decrement -= Assignment Operators in Python - GeeksforGeeks
... # Initializing a variable x = 5 # Incrementing the variable by 1 # Equivalent to x = x + 1 x += 1 # Displaying the result print("Incremented value:", x) ... We do not have a specific decrement operator in Python (like -- in some other ...
Published   April 30, 2024
Discussions

[Python] How do you increment/decrement values in a list?

x -= 1 conceptually means "create a new number object that has the value one less than x and make x refer to that object." This does not affect the list at all, because the list is still referring to the old object.

Use a list comprehension or iterate by index. See this thread from just the other day.

More on reddit.com
🌐 r/learnprogramming
4
5
December 7, 2010
Python lacks pre-increment/decrement; `++count` is syntactically valid but inert - TestMu AI Community
How can I utilize pre-increment and pre-decrement operators (++, --) in Python, similar to their usage in C++? Also, why does ++count execute without modifying the variable’s value? More on community.testmu.ai
🌐 community.testmu.ai
0
April 23, 2024
How do increment and decrement operators work in Python? - Python - Data Science Dojo Discussions
I’m trying to understand the behavior of increment and decrement operators in Python. Can someone explain how they work? For example, when I try to increment or decrement a variable using the ++ or – operators, I get a syntax error. x = 5 x++ # gives syntax error x-- # gives syntax error ... More on discuss.datasciencedojo.com
🌐 discuss.datasciencedojo.com
1
0
April 4, 2023
How to decrement using a for or while loop?
Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today. Start your free trial ... I am new to Python programming. The code below works just fine but I want to decrement the initialized amount of tickets which is 100 until it hit ... More on teamtreehouse.com
🌐 teamtreehouse.com
7
April 9, 2019
🌐
CodeGym
codegym.cc › java blog › learning python › increment and decrement in python
Increment and Decrement in Python
November 11, 2024 - For example, a for loop with a negative step in range() can allow you to loop backwards. ... This loop prints numbers from 5 to 1, decrementing by 1 each time. And there you have it! Although Python doesn’t include ++ and -- operators, it offers plenty of straightforward ways to increment and decrement values.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-decrement-a-python-for-loop
How to Decrement a Python for Loop - GeeksforGeeks
July 23, 2025 - In this example, the range(4, -1, -1) function generates a sequence starting from 4 and decrementing by 1 until reaching -1 (exclusive). The for loop iterates over this sequence, printing each value in reverse order.
🌐
TutorialsPoint
tutorialspoint.com › increment-and-decrement-operators-in-python
Increment and Decrement Operators in Python?
August 23, 2023 - Python does not have unary increment/decrement operator (++/--). Instead to increment a value, use to decrement a value, use − Python does not provide multiple ways to do the same thing .
🌐
Runestone Academy
runestone.academy › ns › books › published › fopp › SimplePythonData › UpdatingVariables.html
2.13. Updating Variables — Foundations of Python Programming
If you try to update a variable ... x was initialized to 6. Updating a variable by adding something to it is called an increment; subtracting is called a decrement....
Find elsewhere
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › perform for loop decrement in python
Perform For Loop Decrement in Python - Spark By {Examples}
May 31, 2024 - If you want to use range() with decrement for a loop in Python, you can set the step parameter to a negative value.
🌐
LearnPython.com
learnpython.com › blog › decrement-in-python-for-loop
How to Decrement a Python for Loop | LearnPython.com
August 22, 2022 - We can also set the step parameter to some other value (like -3) and the for loop will decrement by 3 instead of 1. Let's modify the previous example and output the results: >>> for i in range(9, -1, -3): ... print(i) ... 9 6 3 0 · We can also define a list of elements and display them in reverse order based on the list length. If you don’t remember lists and other Python data structures, I encourage you to read more about the difference between lists, tuples, and dictionaries before you continue.
🌐
Scaler
scaler.com › home › topics › increment and decrement operators in python
Increment and Decrement Operators in Python - Scaler Topics
March 12, 2024 - In Python programming, simplicity is frequently associated with elegance. The Python Decrement Operator, denoted by -=, exemplifies this concept by offering a simple and expressive technique for reducing variables.
🌐
Python.org
discuss.python.org › ideas
Increment, decrement... Can we have inc(), dec() functions in Python? feature request :) - Page 2 - Ideas - Discussions on Python.org
December 4, 2022 - No. It is nothing like next. I’ve already given code using Python syntax that shows how Pascal inc and dec work. Unfortunately you can’t run that code, because they are don’t work in Python, but you can surely follow the input and the expected result. Let’s try again: x = 15 inc(x) # There is NO ASSIGNMENT HERE. assert x == 16 # But like magic, x has a new value!
🌐
TestMu AI Community
community.testmu.ai › ask a question
Python lacks pre-increment/decrement; `++count` is syntactically valid but inert - TestMu AI Community
April 23, 2024 - How can I utilize pre-increment and pre-decrement operators (++, --) in Python, similar to their usage in C++? Also, why does ++count execute without modifying the variable’s value?
🌐
Data Science Dojo
discuss.datasciencedojo.com › python
How do increment and decrement operators work in Python? - Python - Data Science Dojo Discussions
April 4, 2023 - I’m trying to understand the behavior of increment and decrement operators in Python. Can someone explain how they work? For example, when I try to increment or decrement a variable using the ++ or – operators, I get a syntax error. x = 5 x++ # gives syntax error x-- # gives syntax error ...
🌐
Team Treehouse
teamtreehouse.com › community › how-to-decrement-using-a-for-or-while-loop
How to decrement using a for or while loop? (Example) | Treehouse Community
April 9, 2019 - ") ticket_left = ticket_left - num_tickets exit_while_loop = str(input(“ Do you want to exist?. Enter ‘Y’ for yes and ‘N’ for no ”) if exit_while_loop == Y: break ... Thank you Christian. I wanted to make my code a slight different because I did not want to copy yours and find the root cause why code was executing the way I wanted it to. Last night, I was able to loop successfully but I could not get it to decrement correctly.
🌐
Squash
squash.io › how-to-use-increment-and-decrement-operators-in-python
How to Use Increment and Decrement Operators in Python
November 14, 2023 - Python supports the use of the += and -= operators to increment and decrement variables, respectively. These operators are shorthand notations that combine addition or subtraction with assignment.
🌐
Llego
llego.dev › home › blog › a comprehensive guide to increment and decrement operators in python
A Comprehensive Guide to Increment and Decrement Operators in Python - llego.dev
May 9, 2023 - Increment and decrement operators are useful constructs in many programming languages that allow you to easily increment or decrement a variable by 1. Python supports two unary operators for this purpose - ++ and --. However, the behavior of these operators differs from languages like C, C++, or Java.
🌐
iO Flood
ioflood.com › blog › python-increment-by-1-quick-and-easy-examples
Python Increment By 1 | Quick and Easy Examples
March 12, 2024 - For instance, if you have a variable x with a value of 5, you can increment it by 1 using x += 1. After this operation, x will hold a value of 6. Similarly, the -= operator is used to decrement a value.