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 (2015) Python Data Types String Formatting

Damn. I forget what to do.

I'm obviously missing something, but I forget what. I haven't had consistent time to work on this.

strings.py
name = 'Sean'
subject = "Treehouse loves {}.format('Sean')"

3 Answers

angel moreta
angel moreta
2,912 Points

Inside of .format() <—- type name instead of “Sean”

Antonio De Rose
Antonio De Rose
20,882 Points
#treehouse question

#OK, now use .format() on the string "Treehouse loves {}" to put your name into the placeholder. Assign this to the #variable subject (so start with subject =).
#You do not need to print() anything.

#treehouse end of question

name = 'Sean'
subject = "Treehouse loves {}.format('Sean')" #the name should print instead of the placeholder
#if you directly place the your name, there is no value for the placeholder
#you are saving a variable at the start in the name of name with the value in it

subject = "Treehouse loves Sean"
#above is a direct print

subject = "Treehouse loves {}" #we want something to substitute {}, hence we are reserving place

#now, what do we want there is the name which is in the form of a variable, and
#when the python code runs, it will interpolate the variable with the placeholder
#and put the value at the right place
#how could be the code interpolated

subject = "Treehouse loves {}"
#have to concatenate, to join a string with the format method
#why format method - that will help interpolating the name variable with the value replacing the {}

subject = "Treehouse loves {}.format('Sean')" #replace 'Sean' with the variable name you assigned
#hint - think of where would the dot operator comes, the place you have put is wrong
Antonio De Rose
Antonio De Rose
20,882 Points

absolutely, .format(name), will interpolate the name variable's value inside {} place, when the code is run.