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

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

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

2 Answers

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,555 Points

What do you mean? Is it for a challenge?