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:

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

This will output:

1,234,567

Watch a course Python - The Practical Guide

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

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

This will also output:

1,234,567