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

Abdullah Jassim
Abdullah Jassim
4,551 Points

How do you add string values to {} without the print function?

Hi,

I tried the following way but all my answers are wrong. Can you please advise what am I? I know it says dont use PRINT how else do you do it?

Option 1) subject.format(name)

Option 2) print(subject.format(name))

strings.py
name = "jassim"
subject = "Treehouse loves {}"
subject ="Tree house loves {}".format(name)

1 Answer

Stuart Wright
Stuart Wright
41,120 Points

The final line of your code shows exactly how to do it. The challenge is just failing you because you left a space between Tree and house when it should be one word:

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

Also note that I deleted your second line in the solution above. There's no need for that step since you define subject on the next line.

Abdullah Jassim
Abdullah Jassim
4,551 Points

Thanks for the quick turnaround. Much appreciated!