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 trialAndrew Padilla
Courses Plus Student 207 PointsWhy would the "format" go after an argument? "You just bought {} {}.".format(3, "fidget spinners")
I am confused on the format function following after the initial quotation of "You just bought {} {}.".format(3, "fidget spinners"
Why wouldn't we just start another line to do the format? I feel like this method may just confuse learners since we did it previously another way.
1 Answer
Jason Wiram
42,762 PointsThe format method is not following an argument is this example. It is helpful to identify the parts individually.
"You just bought {} {}.".format(3, "fidget spinners")
has the following:
- a String of
"You just bought {} {}."
(the brackets are special characters but it is still a single String) - a String method of
.format()
- two arguments to the
.format()
method of(3, "fidget spinners")
You could (as in the video) create a variable and set it to the value of the string and then (on a separate line) call .format()
on the variable (passing in the arguments). This would accomplish the same thing.