+4 votes
in Programming Languages by (73.8k points)
I want to add a thousand-separator to numbers i.e. commas between three-digit groups. How can I do it in Python?

E.g.

12345678  => 12,345,678

1 Answer

+1 vote
by (349k points)
selected by
 
Best answer

You need to format your number. Just add a comma before the type code.

Here is an example:

>>> a=12345678
>>> '{0:,d}'.format(a)
'12,345,678'


...