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
Anthony Lopez
963 PointsWhat is .format?
Why does he use .format to print the name at the end?
Couldn't he have just put print('Have a great day', first_name, '!')
What is the purpose of print('Have a great day {}!'.format(first_name)) and how does it work?
1 Answer
Steven Parker
243,318 PointsWhich course did you see that in? I'd be surprised if they didn't cover that earlier in the course, or perhaps in a prerequisite.
But the short answer is that "format" will take a string and plug in values into spots indicated with placeholder symbols such as the "{}" you see in that example.
You seemed to have figured it out, since your alternative would produce a similar output. Another way would be to use string concatenation. There are often several choices in programming to achieve a particular result.
Anthony Lopez
963 PointsAnthony Lopez
963 PointsThanks Steven! That makes sense.
Going back in the video I now recognize the part where he covers coerced .format
It was under the strings lesson.
I appreciate the help!