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). Answer from Deleted User on reddit.com
🌐
Alexwlchan
alexwlchan.net › til › 2025 › python-comma-n
Print a comma-separated number in Python with {num:,} – alexwlchan
May 28, 2025 - You can use `{num:,}` to insert a comma every three digits, `{num:_}` to insert an underscore every three digits, and `{num:n}` to insert a locale-aware digit separator.
🌐
GeeksforGeeks
geeksforgeeks.org › python › print-number-commas-1000-separators-python
Print number with commas as 1000 separators in Python - GeeksforGeeks
May 14, 2025 - Format the number and add commas as a thousand separators to use the ',d' formatting syntax in the format() function. ... F-string with replaces function. ... Here, we have used the "{:,}" along with the format() function to add commas every ...
Discussions

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
November 19, 2022
python - Add commas into number string - Stack Overflow
This is documented in PEP 378 -- ... the comma as a thousands separator" ... Sign up to request clarification or add additional context in comments. ... Likely the values would be floats, not integers, so it would be format(value, ",f") 2015-07-31T21:51:01.177Z+00:00 ... You could use locale.currency if TotalAmount represents money. It works on Python <2.7 ... More on stackoverflow.com
🌐 stackoverflow.com
string - How to format a number with comma every four digits in Python? - Stack Overflow
I have a number 12345 and I want the result '1,2345'. I tried the following code, but failed: >>> n = 12345 >>> f"{n:,}" '12,345' More on stackoverflow.com
🌐 stackoverflow.com
python - How to print a number using commas as thousands separators - Stack Overflow
It uses the regular expressions ... get a comma. I say 'after' because the string is reverse at this point. ... For Python versions < 2.6 and just for your information, here are 2 manual solutions, they turn floats to ints but negative numbers work correctly: def format_number_us... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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.
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.

Find elsewhere
🌐
Invent with Python
inventwithpython.com › pythongently › exercise33
Exercise 33 - Comma-Formatted Numbers
Your function returns a string of this number with proper US/UK comma formatting. There is a comma after every third digit in the whole number part. There are no commas at all in the fractional part: The proper comma formatting of 1234.5678 is 1,234.5678 and not 1,234.567,8. These Python assert ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-add-comma-between-numbers
Add Comma Between Numbers - Python - GeeksforGeeks
July 12, 2025 - format() function in Python provides a simple and efficient way to add commas between numbers. ... The :, within the curly braces tells Python to insert commas as a thousand separator.
🌐
Python
peps.python.org › pep-0378
PEP 378 – Format Specifier for Thousands Separator | peps.python.org
March 12, 2009 - For example: ... This technique is completely general but it is awkward in the one case where the commas and periods need to be swapped: format(n, "6,f").replace(",", "X").replace(".", ",").replace("X", ".")
🌐
AskPython
askpython.com › home › adding commas into number string
Adding commas into number string - AskPython
February 27, 2023 - Adding commas to an integer string ... several built-in methods can be used to achieve this goal, such as the format() function and the locale module. These methods can format numbers ......
🌐
Littlecolumns
littlecolumns.com › learn › python › f-strings
Formatting output with f strings - Python's Not (Just) For Unicorns
We learned about f strings, which are a nicer way to print and format strings. 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. Next up: Project - Moon Measurer with Dictionaries · Hi, I'm Soma. I'm writing PNJ4U because bad tutorials make me grumpy. You think it's your fault you can't code? No way, friend, Python's not (just) for unicorns!
🌐
Seqera Community
community.seqera.io › ask for help
Number formatting "comma" doesn't seem to work - Ask for help - Seqera Community
January 16, 2024 - I’m trying to use the hint regarding numerical formatting that is provided here, understanding this as python-style format string. However, I’m unable to cause the formatting to use comma (,) as the thousands separator (underscore works…) Here’s a simple example: custom_data: test: plot_type: "table" headers: value: format: "{:,.2f}" sp: test: fn: "hello.txt" and hello.txt contains: sample value test 100000.55555 The resulting html has the following: i.e. t...
🌐
Streamlit
discuss.streamlit.io › using streamlit
Format Integer With Comma Using Python Printf - Using Streamlit - Streamlit
March 30, 2020 - I have built a slider that has integer values between, say, 0 and 2,000,000. I would like to display the numbers with thousands-commas-separator. The documentation states: format (str or None) – A printf-style format st…
🌐
Bobby Hadz
bobbyhadz.com › blog › python-format-number-thousands-separator-2-decimals
Format number with comma as thousands separator in Python | bobbyhadz
April 9, 2024 - As noted in the docs, the , option signals the use of a comma for a thousands separator. The n integer presentation type is used for a locale-aware separator. You can also use the str.format() method to format a number with a comma as the thousands ...
🌐
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 - To format thousand separators for ... f"{x:,}" In this function, we use Python’s f-string formatting syntax to format the number with commas as thousand separators ({x:,})....
🌐
TestMu AI Community
community.testmuai.com › ask a question
Print Number with Commas in Python - TestMu AI Community
December 25, 2024 - How can I print a number with commas as thousands separators in Python? For example, I want to convert the integer 1234567 into 1,234,567. It does not need to be locale-specific, meaning I just want to use commas as the…
🌐
Python
docs.python.org › 3 › library › string.html
string — Common string operations
If the numerical arg_names in a format string are 0, 1, 2, … in sequence, they can all be omitted (not just some) and the numbers 0, 1, 2, … will be automatically inserted in that order. Because arg_name is not quote-delimited, it is not possible to specify arbitrary dictionary keys (e.g., the strings '10' or ':-]') within a format string.
🌐
AskPython
askpython.com › home › how to print a number using commas as separators?
How to print a number using commas as separators? - AskPython
March 31, 2023 - The curly braces contain data that we want to replace the string. Let’s see the example of using an f-string as a commas separator. ... Here, the ‘Number’ is assigned with the integer value.