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.

Python Python Basics Types and Branching If, Else and Elif

I really want to know why we should use this {}!".format ??

I really want to know why we should use this {}!".format ??

2 Answers

Mel Rumsey
.a{fill-rule:evenodd;}techdegree seal-36
Mel Rumsey
Treehouse Staff

Hi Sohaib Abdullah Sohaib!

If you are wondering how .format works and why we use it:

Using .format() and passing in what you want inserted into the {} is one way to use variables in your strings.

In the video he uses the name example. The name changes based on the users input. So if you want say "Hi my name is, Mel". It is always going to say Mel. But if you format the string to be, print("Hi my name is {}".format(name))

The string changes based on what is entered as the name variable so it could be anything. format() just gives you more versatility.

But if you were wondering why we are using .format vs the f string syntax, Kenneth is just showing you how .format() works. f string will be covered and used in future videos. :)

I hope this answers your question 🎉

Mischa Potter
Mischa Potter
2,553 Points

What do you mean? Is it for a challenge?