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

Nathan Cha
Nathan Cha
1,695 Points

how to?

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

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

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Nathan! Here's a tip:

:bulb: Try not to (at least during challenges) do things the challenge doesn't specifically ask for. Even if functional outside the challenge, it can still cause the challenge to fail.

On to the problem. See those curly braces? We use the .format method on our string to tell it to put the value of a variable in that spot. So we want to immediately follow the string with the .format method. All on the same line. Take a look at my solution:

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

Happy coding! :smiley: