Issue
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
Solution
Try using this:
>>> x = 1_000_000
>>> print(f"{x:_}")
1_000_000
Another way would be to use format
explicitly:
>>> x = 1_000_000
>>> print(format(x, '_d'))
1_000_000
Answered By - Sayandip Dutta
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.