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

WILLIAM GILLILAND
WILLIAM GILLILAND
1,393 Points

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

ok

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

2 Answers

Steven Parker
Steven Parker
229,921 Points

:point_right: Here are a few hints:

  • when assigning, the variable name goes on the left, followed by an equal-sign ("="), then the value
  • the format method should be applied directly to the string being formatted (not the one being assigned)
  • the format method takes the value(s) being substituted into the string as the argument(s)
  • the format string given by the challenge should be used as-is

You need to set a string before you use the format, and you have a typo.

Your code should look something like this:

name = "Bill"

my_str = "Treehouse loves {}".format(name)

I hope this clears things out :)