Skip to content

How to print a number using commas as thousands separators

In Python, you can use the built-in function format() to print a number with commas as thousands separators. Here is an example:

Print a number using commas as thousands separators in Python with format method

python
x = 1234567
print("{:,}".format(x))

This will output:


console
1,234,567

You can also use the f-string (f"")

Print a number using commas as thousands separators in Python with f-strings

python
x = 1234567
print(f"{x:,}")

This will also output:


console
1,234,567

Do you find this helpful?

Dual-run preview — compare with live Symfony routes.