f-strings

f-strings (formatted string literals) allow us to easily format and interpolate variables or expressions directly within a string.

To create an f-string, you prefix the string with the letter `f` and enclose any variables you want to include within curly braces `{}`. Here's an example:

name = "Alice"
age = 15
message = f"My name is {name} and I am {age} years old."
print(message)  # Output: My name is Alice and I am 15 years old.
My name is Alice and I am 15 years old.
In this code, we define an f-string called `message` that includes the variables `name` and `age` within curly braces. The values of the variables are automatically formatted and interpolated into the string when it is printed using the [print function](/tutorials/print).