Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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...