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

Although I use placeholder in code, result gives me "be sure to use placeholder" answer. Can you help why I m wrong.

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

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

2 Answers

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Yagiz, you can simplify the first part, that may make it clearer in regards to what you have to do.

Calling the format method on a string won't actually change the string. If you want to change the value, you have to re assign the value (see below).

name ="{}"
name.format("yagiz")
print(name)  # {}

name ="{}"
name = name.format("yagiz")
print(name)  # yagiz

There's no requirement in this case to use the format method to create the name variable, it's easier to just declare it and assign the value. Also make sure you are using the value of name in the format method and not hard-coding it.

name = 'Yagiz'
subject = 'Treehouse loves {}'.format(name)

thanks for answer :)