0d: 00h: 00m: 00s

šŸŽ Get 3 extra months of learning — completely FREE

That's 90 extra days to master new skills, build more projects, and land your dream job.

Become a PRO
Background Image

šŸŽ Get 3 extra months of learning completely FREE

Become a PRO
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.