Python Python Basics (2015) Python Data Types String Formatting

how to use format?

how to use format function in this code
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
Jennifer Nordell
Treehouse Staff

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