How to use F-String in Python

In this tutorial, you will learn about the F-string. F-strings provide a clean and efficient way to format strings with variables and expressions. They offer improved readability and reduce the need for string concatenation or complex formatting functions.

F String in Python

F-strings in Python, introduced in version 3.6, make it easy to insert variables and expressions into strings. By placing an ‘f’ before the quotation marks, you can include variables directly inside curly braces {}, making your code more readable and concise.

name = "Varsha"
age = 20

message = f"My name is {name} and I am {age} years old."
print(message)

output:

My name is Varsha and I am 20 years old.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top