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

Jason Lucero
Jason Lucero
6,969 Points

String Formatting part 2 is wrong

Pretty sure I have this right as I checked in the shell.

task is looking to insert variable name into {} inside of another string variable. What I have and checked in the shell is:

name = 'Jason' subject = 'Treehouse loves {}' subject.format(name)

I am getting a failure on this one but when testing it out I get 'Treehouse loves Jason' in the console.

strings.py
name = 'Bob'

subject = 'Treehouse loves {}'
subject.format(name)

1 Answer

Antonio De Rose
Antonio De Rose
20,884 Points
name = 'Bob'

subject = 'Treehouse loves {}' #you gotta use the placeholder continued with the format, assigned to the variable
subject.format(name) #this line is outta scope, of the question


#please go through the video, https://teamtreehouse.com/library/python-basics/python-data-types/strings,
#f you are not getting the first time, do not worry, do it over and over, I did not get the first time, 

#the mentioned video above, if you are able concentrate hard you will do it,
#strings does have a method called format, where it interpolates variables 
#into values, in the mentioned placeholder
Jason Lucero
Jason Lucero
6,969 Points

So I get what your saying here but I think I wasn't wrong just thought about the answer differently coming from Ruby. I guess I just missed the example at 8:10 in the video where he was using .format() on the end of an actual string. Thanks for the reply