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

html - How to custom Bootstrap grid height? -

javascript - pass values from mssql to views in node -

javascript - Understanding ExtJS Framework Syntax -