Friday, October 3, 2025
HomeLanguagesPrint number with commas as 1000 separators in Python

Print number with commas as 1000 separators in Python

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.

Examples

Input : 1000000
Output : 1,000,000

Input : 1000
Output : 1,00

Method 1: using f-string

F-strings provide a concise and convenient way to embed python expressions inside string literals for formatting. The inner part within the curly brackets : , says to format the number and use commas as thousand separators.

Example 1:

Format the number and add commas as a thousand separators to use the ‘,d’ formatting syntax in the format() function.

Python3




num = 1000000000
 
print(f"{num:,d}")


Output

1,000,000,000

Example 2:

F-string with replaces function.

Python3




res = f'{10000000:,}'.replace('.',',')
print(res)


Output

10,000,000

Method 2: string.format()

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. 

Example 1:

Numbers with an integer.

Python3




res = '{:,}'.format(1000000)
print(res)


Output

1,000,000

Example 2:

Numbers with decimal.

Python3




num = 123456.1234567
 
res = '{:,.2f}'.format(num)
print(res)


Output

123,456.12
RELATED ARTICLES

Most Popular

Dominic
32332 POSTS0 COMMENTS
Milvus
85 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11868 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11929 POSTS0 COMMENTS
Shaida Kate Naidoo
6819 POSTS0 COMMENTS
Ted Musemwa
7080 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6776 POSTS0 COMMENTS