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
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
408

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.

🌐
GeeksforGeeks
geeksforgeeks.org › python › print-number-commas-1000-separators-python
Print number with commas as 1000 separators in Python - GeeksforGeeks
May 14, 2025 - ... Here, we have used the "{:,}" along with the format() function to add commas every thousand places starting from left. This is introduced in Python and it automatically adds a comma on writing the following syntax.
Discussions

How do I put commas between numbers?
Say this is your number. a_number = 1234567890 You can add the commas like this print(format(a_number, ",")) or like this. print(f"{a_number:,}") Either way, what you're doing here is using a "format specifier" to create a string from the number formatted the way you like. A , means to format your integer or floating point number with commas every third numbers to the left of the decimal. You can see the full list of format specifiers here in the documentation (though TBH it's a bit hard to find what you need in it). More on reddit.com
🌐 r/learnpython
7
11
October 24, 2021
Can anyone help me with this problem?
Write a function named format_number that takes a non-negative number as its only parameter. Your function should convert the number to a string and add commas as a thousands separator. For example, calling format_number(1000000) should return "1,000,000". More on discuss.python.org
🌐 discuss.python.org
0
0
November 19, 2022
How to use python with comma (,) instead of dot (.) as decimal separator?

You convert it before printing.

>>> print(str(3.5).replace(".",","))
3,5

Above code converts 3.5 to string, then replaces dot with comma.

More on reddit.com
🌐 r/learnpython
5
2
July 5, 2018
what is the benefit of f_strings VS commas in python?
Because most of the time you are not passing the string to print but something else that does not do the same thing that print does with multiple arguments. More on reddit.com
🌐 r/learnprogramming
48
52
July 12, 2024
🌐
Littlecolumns
littlecolumns.com › learn › python › f-strings
Formatting output with f strings - Python's Not (Just) For Unicorns
They work like fill-in-the-blanks with our variables, and all you need to do is add a f at the beginning of the string! F-strings also let us do fun tricks like rounding and adding commas if we have long decimals or large numbers.
🌐
Alexwlchan
alexwlchan.net › notes › 2025 › python-comma-n
Print a comma-separated number in Python with {num:,} – alexwlchan
May 28, 2025 - If you use the n format specifier, you get a locale-aware digit separator every three digits. When I start a new Python REPL session, there’s no locale, so there’s no digit separator: ... >>> locale.setlocale(locale.LC_NUMERIC, "fr_FR") >>> f"{num:n}" '123\u202f456\u202f789' >>> print(_) 123 456 789
🌐
W3Schools
w3schools.com › python › python_string_formatting.asp
Python String Formatting
To format values in an f-string, add placeholders {}, a placeholder can contain variables, operations, functions, and modifiers to format the value. ... A placeholder can also include a modifier to format the value.
🌐
Python.org
discuss.python.org › python help
Can anyone help me with this problem? - Python Help - Discussions on Python.org
November 19, 2022 - Write a function named format_number that takes a non-negative number as its only parameter. Your function should convert the number to a string and add commas as a thousands separator. For example, calling format_numb…
Find elsewhere
🌐
mkaz.blog
mkaz.blog › working-with-python › string-formatting
Python String Formatting: Complete Guide
The % formatting method is Python’s oldest string formatting approach, but it’s error-prone and less readable than modern alternatives. ... # ERROR: Type mismatch name = "Alice" age = 25 try: result = "Name: %d, Age: %s" % (name, age) # Wrong types! except TypeError as e: print(f"Error: {e}") # TypeError: %d format: a number is required, not str # FIX: Use correct format specifiers result = "Name: %s, Age: %d" % (name, age) print(result) # Name: Alice, Age: 25 # ERROR: Wrong number of arguments try: result = "%s and %s living together" % ("cats",) # Missing argument except TypeError as e: print(f"Error: {e}") # TypeError: not enough arguments for format string # FIX: Provide all required arguments result = "%s and %s living together" % ("cats", "dogs") print(result) # cats and dogs living together
🌐
Built In
builtin.com › data-science › python-f-string
Guide to String Formatting in Python Using F-strings | Built In
F-string is a way to format strings in Python. It was introduced in Python 3.6 and aims to make it easier for users to add variables, comma separators, do padding with zeros and date format.
🌐
Real Python
realpython.com › how-to-python-f-string-format-float
How to Format Floats Within F-Strings in Python – Real Python
April 24, 2024 - This time, you’ve used multiple replacement fields in the same string. The first one formats a literal number, the second formats the result of a calculation, while the third formats the return value from a function call. Also, by inserting a comma (,) before the decimal point (.) in the format specifier, you add a thousands separator to your final output. In everyday use, you display numbers with a fixed amount of decimals, but when performing scientific or engineering calculations, you may prefer to format them using significant figures.
🌐
YouTube
youtube.com › make data useful
Python F String Formatting Adding Commas to Numbers - YouTube
Quick tutorial on how to make numbers easier to read in Python and data science using underscores on the input value and f string formatting on the output. H...
Published   March 2, 2024
Views   1K
🌐
CopyProgramming
copyprogramming.com › howto › python-python-format-number-with-commas-and-decimal
Python Format Numbers with Commas and Decimal Places: Complete 2026 Guide
December 9, 2025 - For performance-critical applications processing thousands of formatted numbers, f-strings provide measurable advantages. F-strings (f"{number:,.2f}") are the modern standard for Python 3.6+, offering superior performance and readability · Comma separator (,) and decimal precision (.2f) can be combined in a single format specifier for clean, readable code
🌐
CopyProgramming
copyprogramming.com › howto › how-to-format-a-float-with-a-comma-as-decimal-separator-in-an-f-string
Python: Formatting a Float Value in an f-string with Comma as Decimal Separator: A Guide
April 17, 2023 - To enable machine control in Python, I save the outcome to a text-file, which can be easily transferred to Excel. As Excel in the Netherlands uses a comma as the separator, I prefer to have the "position" outcome in the text-file as 123,456. To achieve this, I utilize the f-string method as follows:
🌐
Sling Academy
slingacademy.com › article › python-how-to-format-large-numbers-with-comma-separators
Python: How to format large numbers with comma separators - Sling Academy
June 4, 2023 - Just enclose your number in a pair of curly braces {} within an f-strings, then use a comma as the format specifier.
🌐
Java2Blog
java2blog.com › home › python › add commas to string in python
Add Commas to String in Python [7 ways] - Java2Blog
October 26, 2022 - Using the replace() function. How To Add Commas to String in Python to Represent Numbers in A Currency? Using the format() function.
🌐
Codementor
codementor.io › community › why is there an f before this string? an introduction to f-strings and string formatting
Why is there an f before this string? An introduction to f-strings and string formatting | Codementor
July 27, 2019 - The , tells python to format the number with commas, so 1200000 becomes 1,200,000 (if you're building an international application, remember that in some countries the , and . symbol are reversed).
🌐
Codegrepper
codegrepper.com › code-examples › python › format+number+with+commas+python
format number with commas python Code Example
February 21, 2021 - num = int(input()) #1234567 print(f"{num:,}") #1,234,567 #Hope this helps:)
🌐
Xspdf
xspdf.com › resolution › 52802977.html
Professional .NET SDK to create, edit, save PDF and Excel, convert pdf to images, import and export data from excel, OCR text from image in C#.
All SDKs are complete .NET development librarys, can be compatible with WinForms, WPF and ASP.NET web applications · Create new PDF and Excel files, update and edit an existing PDF or Excel document