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

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -