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

Blake Rogers
Blake Rogers
3,069 Points

OK, so now use .format() on the string "Treehouse loves {}" to put your name into the placeholder. Assign this to the va

OK, so now use .format() on the string "Treehouse loves {}" to put your name into the placeholder. Assign this to the variable subject again.

help me with this

Ken Alger
Ken Alger
Treehouse Teacher

What have you tried?

Blake Rogers
Blake Rogers
3,069 Points

This

name = "Dylan" subject = "Treehouse loves {}" subject = print(subject.format(name))

name = "Dylan" subject = "Treehouse loves {}" print(subject.format(name))

name = "Dylan" subject = "Treehouse loves {}" subject = subject.format(name)

6 Answers

name =(Bobcat) subject = "Treehouse loves {}".format(name)

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Blake;

You are definitely close and have the right idea. The challenge is looking for the format() method to be directly attached to the string that is assigned to the subject variable. We don't need to print anything.

Try doing the subject variable step all in one line and see how that works. :wink:

Happy coding,
Ken

Blake Rogers
Blake Rogers
3,069 Points

Please give me an example.

Ken Alger
Ken Alger
Treehouse Teacher

Sure:

Here's an example, not the answer, but you should be able to get there.

name = "Blake"
statement = "{} can code in Python.".format(name)

Ken

Michael Murphy
Michael Murphy
14,097 Points

I didn't know it had to be on the same line, I tried to apply format on subject as a second step and that wasn't working. Your advice and example helped a lot.

Hi robert, I entered name="Bobcat" subject = "Treehouse loves {}".format(name)

and it didn't work.

It worked i forgot to put = after subject.

I am new to programming but I just cannot get this on workspace but it works fine on the python shell. name = "jacques" subject = "Treehouse loves {} ".format(name) when I use print it works

Sandhya Akkinapalli
Sandhya Akkinapalli
977 Points

name = "Alex" subject = "Treehouse loves {}".format(name)