Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Format numbers in Python

Hi,

I'd like to know if there is a way to format long numbers (integers) the following way.

For example if I have the number 1166832000

can I display it like this: 11 66 832 000

or 11,66,832,000

Thanks

If you are looking for thousand separators you could use this syntax. It will be commas though, not spaces.

num = 132489893342325

print("{0:,}".format(num))

# OUTPUT 
132,489,893,342,325

Since that would be a string output he could then use str.replace(",", " ") to achieve spaces.