Since python3.6, you can use underscore to separate digits of an integer. For example
x = 1_000_000
print(x) #1000000
This feature was added to easily read numbers with many digits and I found it very useful. But when you print the number you always get a number not separated with digits. Is there a way to print the number with its digits separated with underscore.
P.S. I want the output as integer not as string. Not "1_000_000" but 1_000_000
Try using this:
>>> x = 1_000_000
>>> print(f"{x:_}")
1_000_000
Here are details
Another way would be to use format explicitly:
>>> x = 1_000_000
>>> print(format(x, '_d'))
1_000_000
print('{:_}'.format(x))
Output:
1_000_000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With