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

%d, %s for python

I've been using other learning platforms to supplement my python learning and I see some using %d and %s instead of .format. Is this something new, or a matter of preference?

1 Answer

It's an example of printf-style formatting, which is the oldest string formatting technique in Python. The format method was added to address some issues that people tended to run into with that technique.

printf-style formatting works just fine most of the times so it is mostly a matter of preference, but I'm under the impression that use of the format method is more common these days than printf-style formatting.

It's worth mentioning that Python recently added yet another string formatting technique called F-Strings, which allow you to embed variables directly in a string. But it is not usable on Treehouse since it requires Python 3.6 and up whereas Treehouse uses Python 3.5.

Thanks so much for this info. It's really usefu!