Locale-agnostic: use _ as the thousand separator

f'{value:_}'          # For Python ≥3.6

Note that this will NOT format in the user's current locale and will always use _ as the thousand separator, so for example:

1234567 ⟶ 1_234_567

English style: use , as the thousand separator

'{:,}'.format(value)  # For Python ≥2.7
f'{value:,}'          # For Python ≥3.6

Locale-aware

import locale
locale.setlocale(locale.LC_ALL, '')  # Use '' for auto, or force e.g. to 'en_US.UTF-8'

'{:n}'.format(value)  # For Python ≥2.7
f'{value:n}'          # For Python ≥3.6

Reference

Per Format Specification Mini-Language,

The ',' option signals the use of a comma for a thousands separator. For a locale aware separator, use the 'n' integer presentation type instead.

and:

The '_' option signals the use of an underscore for a thousands separator for floating point presentation types and for integer presentation type 'd'. For integer presentation types 'b', 'o', 'x', and 'X', underscores will be inserted every 4 digits.

Answer from Ian Schneider on Stack Overflow
🌐
Python
peps.python.org › pep-0378
PEP 378 – Format Specifier for Thousands Separator | peps.python.org
Common Lisp uses a COLON before the ~D decimal type specifier to emit a COMMA as a thousands separator. The general form of ~D is ~mincol,padchar,commachar,commaintervalD. The padchar defaults to SPACE. The commachar defaults to COMMA. The commainterval defaults to three. ... The ADA language allows UNDERSCORES in its numeric literals.
🌐
GeeksforGeeks
geeksforgeeks.org › python › print-number-commas-1000-separators-python
Print number with commas as 1000 separators in Python - GeeksforGeeks
May 14, 2025 - In this program, we need to print the output of a given integer in international place value format and put commas at the appropriate place, from the right. Let's see an example of how to print numbers with commas as thousands of separators in Python. ... F-strings provide a concise and convenient way to embed python expressions inside string literals for formatting.
Top answer
1 of 16
2569

Locale-agnostic: use _ as the thousand separator

f'{value:_}'          # For Python ≥3.6

Note that this will NOT format in the user's current locale and will always use _ as the thousand separator, so for example:

1234567 ⟶ 1_234_567

English style: use , as the thousand separator

'{:,}'.format(value)  # For Python ≥2.7
f'{value:,}'          # For Python ≥3.6

Locale-aware

import locale
locale.setlocale(locale.LC_ALL, '')  # Use '' for auto, or force e.g. to 'en_US.UTF-8'

'{:n}'.format(value)  # For Python ≥2.7
f'{value:n}'          # For Python ≥3.6

Reference

Per Format Specification Mini-Language,

The ',' option signals the use of a comma for a thousands separator. For a locale aware separator, use the 'n' integer presentation type instead.

and:

The '_' option signals the use of an underscore for a thousands separator for floating point presentation types and for integer presentation type 'd'. For integer presentation types 'b', 'o', 'x', and 'X', underscores will be inserted every 4 digits.

2 of 16
407

I'm surprised that no one has mentioned that you can do this with f-strings in Python 3.6+ as easy as this:

>>> num = 10000000
>>> print(f"{num:,}")
10,000,000

... where the part after the colon is the format specifier. The comma is the separator character you want, so f"{num:_}" uses underscores instead of a comma. Only "," and "_" is possible to use with this method.

This is equivalent of using format(num, ",") for older versions of python 3.

This might look like magic when you see it the first time, but it's not. It's just part of the language, and something that's commonly needed enough to have a shortcut available. To read more about it, have a look at the group subcomponent.

🌐
Reddit
reddit.com › r/python › thousands separator using underscore
r/Python on Reddit: Thousands separator using underscore
June 1, 2019 - Also in Python: print takes input as variadic arguments, with a keyword argument for the separator. Default is a space. ... I think Dutch or French writes thousands seperators like this. Its not like they decided for ' as seperator out of the blue.
🌐
Python.org
discuss.python.org › python help
Can Python have support for number separators? - Python Help - Discussions on Python.org
February 23, 2024 - I see that when I call something like int(2,345,565), it gives an error. Interestingly, in Java, this is supported. Is it a good idea to have something like this in Python?
🌐
Bobby Hadz
bobbyhadz.com › blog › python-format-number-thousands-separator-2-decimals
Format number with comma as thousands separator in Python | bobbyhadz
Use a formatted string literal to format a number with a comma as the thousands separator to 2 decimals, e.g. `result = f'{my_float:,.2f}'`.
🌐
Python.org
discuss.python.org › ideas
Space as a thousands separator in the format specification mini-language - Ideas - Discussions on Python.org
December 1, 2024 - Could I put in a word for spaces as a grouping option in the format specification mini-language? Right now, comma and underscore are available – why not space as well? One doesn’t always want to change the locale to get the international standard for representation of numbers.
Find elsewhere
🌐
Finxter
blog.finxter.com › how-to-print-an-integer-with-commas-as-thousands-separators-in-python
How to Print an Integer with Commas as Thousands Separators in Python? – Be on the Right Side of Change
Using the modern f-strings is, in my opinion, the most Pythonic solution to add commas as thousand-separators for all Python versions above 3.6: f'{1000000:,}'. The inner part within the curly brackets :, says to format the number and use commas as thousand separators.
🌐
Python
peps.python.org › pep-0515
PEP 515 – Underscores in Numeric Literals | peps.python.org
This is a common feature of other modern languages, and can aid readability of long literals, or literals whose value should clearly separate into parts, such as bytes or words in hexadecimal notation. ... # grouping decimal numbers by thousands amount = 10_000_000.0 # grouping hexadecimal addresses by words addr = 0xCAFE_F00D # grouping bits into nibbles in a binary literal flags = 0b_0011_1111_0100_1110 # same, for string conversions flags = int('0b_1111_0000', 2)
🌐
Sololearn
sololearn.com › en › Discuss › 3235225 › thousand-separator-for-float-nums
thousand separator for float nums? | Sololearn: Learn to code for FREE!
Angela , This is a sample that ... is also rounded to the number of digital places This is what the arguments in the curly braces are: `number`: Variable or expression that should be formatted : (colon): After this the ...
🌐
Peterbe.com
peterbe.com › plog › format-thousands-in-python
Format thousands in Python - Peterbe.com
which demonstrates (1) how to do zero-padding (of length 20), (2) the thousands comma, (3) round to 2 significant figures. All useful weapons to be able to draw from the top of your head. ... John S. February 6, 2019 Reply · You can also format numbers with an underscore separator instead of commas (`format(number, '_')`). That has the advantage of being both quickly human-eye-parsable AND python parsable, e.g.
🌐
Rosetta Code
rosettacode.org › wiki › Numeric_separator_syntax
Numeric separator syntax - Rosetta Code
3 weeks ago - The Syntax for separators in numbers, (numeric literals), is given here in the Python documentation.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-format-thousand-separator-for-integers-in-a-pandas-dataframe
How to Format Thousand Separator for Integers in a Pandas DataFrame | Saturn Cloud Blog
December 6, 2023 - In many countries, a comma (,) is used as a thousand separator, while others use a period (.) or a space. For example, the number 1000000 can be written as 1,000,000 (comma-separated), 1.000.000 (period-separated), or 1 000 000 (space-separated).
🌐
Finxter
blog.finxter.com › 5-best-ways-to-format-numbers-with-thousand-separators-in-python
5 Best Ways to Format Numbers with Thousand Separators in Python – Be on the Right Side of Change
This code snippet first sets the locale to ‘en_US.UTF-8’ which uses commas as thousand separators. Then, it formats the number with grouping enabled. The disadvantage is that it requires changing the locale, which might not be desirable in all programs. Introduced in Python 3.6, f-strings offer a concise and readable way to embed expressions inside string literals.
🌐
Python.org
discuss.python.org › ideas
Add underscore as a thousandths separator for string formatting - Ideas - Discussions on Python.org
January 26, 2021 - I can think of two different ways to do this: Special case the _ grouping_option to add an underscore in the thousandths places Add a new format specifier (like float_grouping): format_spec ::= [[fill]align][sign][#][0][width][grouping_option][.precision[float_grouping]][type] fill ::= align ::= " " | "=" | "^" sign ::= "+" | "-" | " " width ::= digit+ grouping_option ::= "_" | "," float_grouping ::= "_" precision ...
🌐
Herrmann
herrmann.tech › en › blog › 2021 › 02 › 05 › how-to-deal-with-international-data-formats-in-python.html
How to deal with international data formats in Python – herrmann.tech
In [1]: import locale ...: locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8') Out[1]: 'de_DE.UTF-8' In [2]: locale.currency(0.5) Out[2]: '0,50 €' In [3]: locale.currency(1000.5, grouping=True) # thousands separator Out[3]: '1.000,50 €' In [4]: print('eine halbe Einheit: ' + locale.format_string('%.2f', 0.5)) eine halbe Einheit: 0,50 In [5]: locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') Out[5]: 'en_US.UTF-8' In [6]: print('half a unit: ' + locale.format_string('%.2f', 0.5)) half a unit: 0.50
🌐
Google Groups
groups.google.com › g › julia-users › c › p6bi_SkHDJ0
Formatting comma thousands separator
For thousands separators, it seems there are many options in fact. x = 10^9 using Formatting s = fmt(",d", x) # python-style format spec (single value) s = format("{:,d}", x) # python-style form expression (multiple values) s = sprintf1("%'d", x) # c-style s = format(x, commas=true) # keyword arguments using StringUtils s = u"\%(x, :commas)"
🌐
ActiveState
code.activestate.com › recipes › 498181-add-thousands-separator-commas-to-formatted-number
Add thousands separator commas to formatted numbers « Python recipes « ActiveState Code
##################################### ... handled on March 12 2010, Alessandro Forghieri def splitThousands( s, tSep=',', dSep='.'): '''Splits a general float on thousands....
🌐
Proinsias
proinsias.github.io › til › Python-Format-strings-thousands-separator
Python: Thousands Separator in Formatted Strings - Looking for data in all the right places…
May 13, 2025 - It’s very easy to add thousands separators to numbers: >>> big_num = 1234567890.123 >>> print(f'{big_num:,}') 1,234,567,890.123 · Twitter Facebook LinkedIn · July 24, 2025 less than 1 minute read · With all the recent hype around large language models (LLMs) and their ability to effortlessly generate code, Pedro Tavares reminds us that it’s worth reflec...