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

Keeper of the Cog Rebecca
Keeper of the Cog Rebecca
480 Points

print(subject.format(name))

Not sure what this question is asking me to do, I did this is workspace and the output was correct, so not sure what work the questions wants me to see

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

3 Answers

Dylan Shine
Dylan Shine
17,565 Points
name = "Dylan"
subject = "Treehouse loves {}".format(name)

You have the right idea, just use the .format function during the variable assignment

[MOD: added ```python markdown formatting -cf]

Keeper of the Cog Rebecca
Keeper of the Cog Rebecca
480 Points

Man I must have missed something in that lesson I might need to review it. Then how would you print() it?

Dylan Shine
Dylan Shine
17,565 Points

If you wanted to print it out, simply use the print function:

print subject or print(subject)

I forget which version of Python uses which syntax.

Keeper of the Cog Rebecca
Keeper of the Cog Rebecca
480 Points

... omg duh! I think I'm making it more difficult than it actually is. In the example from video the way he was formatting the name into the {} was through the print function, it wasn't created in it's own variable...

But like I said I might have missed something or I feel like I did, so I'll review that vid today. Thanks for the help!