DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk1 min

Python Increment and Decrement: There Is No ++ Operator

Python has no ++ or -- operator. Use += 1 to increment and -= 1 to decrement; augmented assignment can differ from explicit reassignment for some targets and objects.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Python has no ++ or -- increment/decrement operator. To change an ordinary numeric variable by one, use x += 1 or x -= 1. The explicit alternatives are x = x + 1 and x = x - 1.

How to increment or decrement a Python variable

Use augmented assignment for the usual case:

count = 4
count += 1  # count is now 5
count -= 1  # count is now 4

+= and -= are augmented assignment operators: they perform an operation and assign its result to the target. For a simple integer variable, these forms clearly express adding or subtracting one. The Python Language Reference describes x += 1 as similar to x = x + 1, but cautions that the effects are not exactly equal in every case.

Why Python does not use ++ or —

Python’s operator-token inventory includes +, -, += and -=, but not ++ or -- as operators. The complete inventory is in the Python Language Reference’s lexical analysis section.

Unary plus is not an increment operation either: +x is a unary arithmetic expression, not an assignment that changes x. To increment the variable, use an assignment such as x += 1. Python’s data model documents unary arithmetic and augmented arithmetic operations separately.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When += and = x + 1 can behave differently

For a simple integer variable, x += 1 and x = x + 1 are usually interchangeable in practice. But augmented assignment evaluates its target once and, when the target’s type supports an in-place operation, may modify the existing object rather than create a replacement. Otherwise, normal binary-operation behavior may apply. This distinction can matter for complex targets or mutable objects, so the two forms should not be treated as universally identical.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.