Formatting numbers in python for display -


i trying output longer integer in more readable manner. how can format string spaces after number of digits?

for example, 12345678 output 1234 56 78

one option use re module, match number regex , reformat it:

import re re.sub(r"(\d{4})(\d{2})(\d{2})", r"\1 \2 \3", "12345678") # '1234 56 78' 

or readability might want format thousand separator:

"{:,d}".format(12345678) # '12,345,678' 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

Ansible warning on jinja2 braces on when -