0Pricing
Python Academy · Lesson

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

  1. f-string Expressions
  2. Format Specifiers
  3. Format Mini-Language
  4. Template Strings and str.format
← Back to Python Academy