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

string - How to format a number with comma every four digits in Python? - Stack Overflow
1309 How to print a number using commas as thousands separators · 98 How do I format a number with a variable number of digits in Python? More on stackoverflow.com
🌐 stackoverflow.com
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
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
Format Integer With Comma Using Python Printf
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 string controlling how the interface should display numbers. More on discuss.streamlit.io
🌐 discuss.streamlit.io
0
0
March 30, 2020
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.

🌐
Alexwlchan
alexwlchan.net › notes › 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.
🌐
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.
Find elsewhere
🌐
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 ......
🌐
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.
🌐
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…
🌐
Invent with Python
inventwithpython.com › pythongently › exercise33
Exercise 33 - Comma-Formatted Numbers
We need to loop starting at the one’s place in the number and moving left, so our for loop should work in reverse: for i in range(len(number) - 1, -1, -1). For example, if number is 4096, then the first iteration of the loop can access number[3], the second iteration can access number[2], ...
🌐
Python
peps.python.org › pep-0378
PEP 378 – Format Specifier for Thousands Separator | peps.python.org
March 12, 2009 - The proposal works well with floats, ints, and decimals. It also allows easy substitution for other separators. 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", ".")
🌐
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...
🌐
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!
🌐
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.
🌐
TutorialsPoint
tutorialspoint.com › article › print-number-with-commas-as-1000-separators-in-python
Print number with commas as 1000 separators in Python
2 weeks ago - # Format floats with commas and 2 decimal places price1 = 3435.242563 price2 = 1234567.89 price3 = 999.5 print(f'{price1:,.2f}') print(f'{price2:,.2f}') print(f'{price3:,.2f}') ... # Using format() method num = 2500000 price = 12345.678 ...
🌐
Codemia
codemia.io › knowledge-hub › path › how_to_print_a_number_using_commas_as_thousands_separators
How to print a number using commas as thousands ...
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
🌐
Mark Needham
markhneedham.com › blog › 2021 › 04 › 11 › pandas-format-dataframe-numbers-commas-decimals
Pandas - Format DataFrame numbers with commas and control decimal places | Mark Needham
April 11, 2021 - That doesn’t work because the LTLA Name column contains string values, which can’t be formatted as a number. We can work around that problem by dropping the LTLA Name column: df.drop(["LTLA Name"], axis=1).style.format("{:.2f}") This works, but we’ve lost the LTLA Name column and the Population column isn’t formatted how we’d like. Instead of passing a single style to style.format, we can instead pass a dictionary of {"column: "style"}. So to style Population with a comma as thousands separator and PercentageVaccinated with two decimal places, we can do the following:
🌐
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 ...