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

Nicole Groenewald
Nicole Groenewald
1,031 Points

Format preference? Or is this just wrong?

Is this a formatting preference that one is used over the other or will it make sense why we're using .format rather than just entering the string the way I did in the last line later? I'm in Python Basics. I'm hung up on it and having a hard time moving forward in the class because each time it comes up my brain is like "why are we doing it this way??"

first_name = input("What is your name?")

print("Have a great day {}!".format(first_name))
print("Have a great day" , first_name, "!")

1 Answer

Steven Parker
Steven Parker
231,198 Points

There are several ways (a few more yet!) to format strings, and the courses expose you to them so that you can recognize them in reading code and choose one that best fits your situation when writing it. Unless a challenge is about a particular formatting method, most challenges allow you to pick any method that produces the correct result.

But be aware of their differences, for example in the statements shown above the second version will add a space between the name and the exclamation point.