How to Write Large Numbers with Underscores in Python
Is 1000000 a million or a hundred thousand? You have to count the zeros. Python lets you write it as 1_000_000 instead, and the underscores change nothing about the number. This guide shows it on Python 3.15.2.
Syntax
<digits>_<digits>
| Part | What it means |
|---|---|
<digits> | One or more digits of the number |
_ | A single underscore between two digits. Python ignores it when it works out the value |
The Python language reference says: "Underscores can be used to group digits for enhanced readability, and are ignored for determining the numeric value of the literal." It adds one rule: "Underscores can only occur between digits."
The Example
A variable holds one million, written as 1_000_000. The script prints it, compares it with 1000000, and adds 1 to it.
Prerequisites
- uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
tokens = 1_000_000
print(tokens)
print(tokens == 1000000)
print(tokens + 1)

Step 2: Run It
uv run python big_numbers.py
1000000
True
1000001

Python printed 1000000, without underscores: they exist only in your code, not in the number. The comparison is True, because 1_000_000 and 1000000 are the same number, and adding 1 works as it does for any number. The command works unchanged in PowerShell.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Two underscores in a row: 1__000 | SyntaxError: invalid decimal literal | Use a single underscore between digits |
An underscore at the end: 1000_ | SyntaxError: invalid decimal literal | Put underscores only between digits |
Expecting print() to show the underscores | print(tokens) shows 1000000 | Format the number: f"{tokens:_}" gave 1_000_000, and f"{tokens:,}" gave 1,000,000 |
FAQ
Does it work for numbers with a decimal point?
Yes. 2_500.75 gave 2500.75. The reference says: "As in integer literals, single underscores may occur between digits to help readability".
Can int() read text with underscores?
Yes. int("1_000_000") gave 1000000.
Conclusion
tokens = 1_000_000 stored one million. Python printed it as 1000000, it compared equal to 1000000, and adding 1 gave 1000001.
Additional Resources
- Integer literals — how whole numbers are written, underscores included.
- Floating-point literals — the same rule for numbers with a decimal point.
- Format specification mini-language — the
_and,options that print separators.
