Underscores in Numbers

We can use underscores in numbers to improve the readability. It comes handy when the numbers are relatively large and difficult to read.

These underscore characters in numbers are for user readability only. Python Interpreter ignores the underscores in numbers.

Example

In the following program, we define a number in x, and use underscores between the digits.

Python Program

</>
Copy
n = 9_000_526_210
print('Number =', n)

Output

Number = 9000526210

We can use the underscores in floating-point numbers as well, as shown in the following program.

Python Program

</>
Copy
n = 9_000_526_210.125632
print('Number =', n)

Output

Number = 900052621

Conclusion

In this Python Tutorial, we learned how to use underscores in numbers to increase the readability of numbers.