Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


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 27,768 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.