Template Strings and str.format
Other formatting tools.
Other formatting tools
Beyond f-strings, Python offers two more formatting tools: the str.format() method and the string.Template class. Each suits different situations.
print('Hello, {}!'.format('World'))str.format basics
str.format() replaces {} placeholders with arguments, in order. It predates f-strings and still appears in lots of code.
msg = '{} is {} years old'.format('Ada', 36)
print(msg)All lessons in this course
- f-string Expressions
- Format Specifiers
- Format Mini-Language
- Template Strings and str.format