
PRO
Keshava
asked

Expert
Apekchhya Shrestha answered
f-strings, or formatted string literals, are a simple way in Python to put variables inside a sentence.
Let’s say we have a variable age
with the value 28
. Without using f-string, we might write:
age = 28
print("My age is", age)
Using an f-string, the same output can be written more cleanly:
age = 28
print(f"My age is {age}")
Both versions will give the same result, but f-strings make it easier to format the output, especially when dealing with multiple variables. For example:
name = "Maria"
age = 28
print(f"My name is {name} and I am {age} years old.")
Try running the code in the code-editor to see it in action. As you move forward, the next lessons will cover the concept in even more depth.
Hope this helps! Feel free to ask if you have any more questions.
Python
This question was asked as part of the Learn Python Basics course.