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
- f-string Expressions
- Format Specifiers
- Format Mini-Language
- Template Strings and str.format