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 Python Basics Types and Branching If, Else and Elif

Shali Dan
Shali Dan
741 Points

Line 8 and 9: Why do we use .format(first_name) when we can use ("Have a great day", first_name) ?

I don't get why they would use {} .format when they can use first_name. Wouldn't that be easier?

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Hey Shali Dan, it seems Craig is attempting to introduce additional ways to format a string.

In the “Have a great day” line, using a simple tuple of arguments fails, since the comma format adds a space between the first_name and the !.

>>> # using comma separation 
>>> first_name = "Craig"
>>> print("Have a great day", first_name, "!")
Have a great day Craig !

>>> # using concatenation works
>>> print("Have a great day " + first_name +"!")
Have a great day Craig!

The latest formatting method f-strings have been optimized to be the fastest method.

Post back if you need more help. Good luck!!!