replacement field
A pair of braces {} in a format string marking where a value will be inserted.
In more detail
Empty braces are filled in order; {0} or {name} choose a specific argument, so a value can be reused or reordered. After a colon comes a format specifier, as in {:.2f}. To print a literal brace, double it.
Example
"{0} {1} {0}".format("a", "b")Related terms
- format method — The string method that returns a copy of a string with each {} replacement field filled in from its arguments.
- f-string — A Python string with an f before the opening quote, in which expressions in curly brackets are replaced by their values.
- format specifier — The instructions after a colon inside a replacement field, such as .2f for two decimal places, that control how a value is shown.
Taught in
- The String Format Method — Hands-on Python: Complete Video Course & Book
- Function Parameters — Hands-on Python: Complete Video Course & Book
- Mad Libs Revisited: Finding The Cues — Hands-on Python: Complete Video Course & Book