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

how do you use .format() without using print()

I seem to be missing something but cant figure it out so far i have this: name = "andrew" subject = "Treehouse Loves {} ".format(name)

from the lecture i was under the impression you would do this: name = "andrew" subject = "Treehouse Loves {} " print(subject.format(name))

please help, none seem to be correct and the lecture does not state it clearly, at least from my point of view. thanks

strings.py
name = "andrew"
subject = "Treehouse Loves {} ".format(name)

1 Answer

Steven Parker
Steven Parker
231,236 Points

The format function just creates a new string.

What you do with that string is up to your program. It might be printed out, but it could also be simply assigned to a variable.

In this challenge, you are asked to use it to assign a variable. You won't need to print anything this time.

Your code above has a stray extra space at the end of the string "Treehouse Loves {} " :point_left: here
Remove that extra space and you should pass the challenge.