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 to use format?

how to use format function in this code

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

2 Answers

Hey Ashmit! Your super close, but you have to format outside of the string. So after "example {}".format(whatYouWantToFormat).

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I feel like you're doing pretty well here, but your quotation marks are a bit misplaced. The quotation marks should be placed around the string to be formatted and then the format method should be directly on the end of that string. Here's an example:

you = "Ashmit"
greeting = "Hi there, {}".format(you)

The ending value of greeting will be "Hi there, Ashmit" Also, notice how I put a space immediately before the {}. Currently, there is no space in your code between the "loves" and the {} which means that once you fix the quotation mark placement the value stored in the subject variable would be "Treehouse lovesAshmit" instead of "Treehouse loves Ashmit".

Hope this helps! :sparkles:

Thanx ma'am for the help...