0Pricing
Python Academy · Lesson

f-string Expressions

Embed expressions in strings.

What is an f-string?

An f-string is a string prefixed with f that lets you embed Python expressions directly inside braces {}. Introduced in Python 3.6, they are the clearest way to build strings.

name = 'Ada'
print(f'Hello, {name}!')

Embedding variables

Any variable name placed in {} is replaced by its value, converted to a string automatically.

age = 30
city = 'Istanbul'
print(f'I am {age} and live in {city}.')

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