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 trialUriel meneses
4,944 Pointsi need help on task 2 using the .format need help
how do i correctly set it up with the variable?
name = "uriel"
subject = " () () ".format "Treehouse loves { name}"
1 Answer
Brian Boring
Courses Plus Student 3,904 PointsClose, but you got it a little backwards there. The statement is made with the curly brackets. The .format method then calls what will be put into the curly brackets, in this case (name). subject = ("Treehouse loves {}".format(name))
Johannes Scribante
19,175 PointsJohannes Scribante
19,175 PointsHi Uriel,
When using the format method, there is a specific format (excuse then pun) you need to use.
first define the string or variable of the string. In the string you would define placeholders you want the format method to fill using
{}
. Then you pass the format method you objects you want to place inside your placeholders using.format(name, 'string', 3)
.variable = 'Variable'
my_string = 'this string will display variable a: {}, string hello: {} and a number: {}'.format(variable, 'hello again', 4)
print(my_string)
Hope this helps