Ends in 7 days

BLACK FRIDAY: Receive 83% off Programiz PRO

+🎁 Buy 1 year, gift 1 year FREE — Split with a friend for just $49.50 each

Start FREE trial →
Background Image

Buy 1 year, Gift 1 year —completely FREE

Start FREE trial →
Keshava Harshith Manikyala
last year
Keshavacountry asked

What is meant by f-strings in Python?

Apekchhya Shrestha
Expert
last year

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.