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
Tristan Jahnke
2,843 PointsWhen dealing with variables and what not within output to a screen is it better to use in string formatting
ie is it better to use {} with .format() or to input the variable names directly into the line ie print("Hello,", users_name)? just curios
1 Answer
Steven Parker
243,656 PointsBoth methods achieve the same result, it's basically just "programmer's choice". Format might be a better choice when you have multiple substitutions and/or when the placeholder has text on both sides.
Tristan Jahnke
2,843 PointsTristan Jahnke
2,843 PointsI get that but what is it that most use/what is the default i guess. I see a lot prefer .format but is that the best way?
Steven Parker
243,656 PointsSteven Parker
243,656 PointsWhat I meant by "programmer's choice" is that neither is "better", so feel free to use the one that you prefer.