python / beginner
Snippet
Formatted String Literals (f-strings)
F-strings provide a concise and convenient way to embed expressions inside string literals for formatting.
snippet.py
1
2
3
name = 'Alice'age = 25print(f'Hello, {name}. You are {age} years old.')
Breakdown
1
name = 'Alice'
Assigns a string value to a variable.
2
print(f'Hello, {name}...')
Uses the 'f' prefix to allow variables inside curly braces to be evaluated directly within the string.