Samuel toluwanmi ibitola
last year
Samuelcountry asked

Why is f-string important?

Kelish Rai
Expert
last year
Kelish Rai answered

F-strings are important in Python because they make it easier and cleaner to format strings.

For example, instead of formatting the output with the + operator like this:

firstName = "John"
lastName = "Doe"

print("My name is " + firstName + " " + lastName)

You can simply do this:

firstName = "John"
lastName = "Doe"

print(f"My name is {firstName} {lastName}")

As you can see, it's much easier to format the strings using f-strings than using string concatenation.

Python
This question was asked as part of the Getting started with Python course.