Formatting number with an underscore in Python

Published

May 10, 2022

Today I learn printing numbers with an underscore in Python.

In Python, you can format a large number with an underscore to make it more readable. For example, the following example shows the format of a number with an underscore:

temp = 1_000_00
print(temp)
100000

But, printing a number with an underscore gives the number without the underscore. If you want to print a number with an underscore, you can use the following syntax:

print(f'{temp:_}')
print(f'{temp:,}')
100_000
100,000

See you tomorrow!