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


Advantage of print('string'{}.format()) vs. print(stringname.format())?

When would it be preferable to use the former over the latter? It would seem that the latter approach would be more efficient by not having to type out a long string and just using the variable instead.

1 Answer

Jeff Muday
Jeff Muday
Treehouse Moderator 28,717 Points

The first approach is better for short print snippets-- especially those that are way under the PEP-8 character line-limit. The second approach is preferred for longer templates, especially when you split your string over multiple lines.

Efficiency-wise, both approaches are the same.