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

String formatting, why isn't this working

I think my code is correct, but I don't why it isn't working

strings.py
name = "Sud"

subject = "Treehouse Loves {}".format("Sud")

I've even tried to do this.

.format(name)

3 Answers

There you go

name = "Sud"

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

With the Formatter the {0} becomses the name variable (parameter). 0 means it gets the first varaible

Another example

name1 = "Sud"
name2 = "Ben"
name3 = "Chris"

subject = ("Treehouse loves {0}, {1} and {2}").format(name1, name2, name3)

this makes the string to "Treehouse loves Sud, Ben and Chris

more information: https://docs.python.org/2/library/string.html#format-examples

Okay, thanks

Okay, thanks