Python f-strings is a new string formatting syntax in Python 3.6 and later, which can be used to create formatted strings using expressions that are evaluated at runtime.
f-strings in Python are a new feature that makes it easier to format strings. They can be used for both string interpolation and string formatting.
This tutorial will teach you how to use the Python f-string and when it might be helpful. Read on for related examples.
Table of Contents
Python f-strings: How to Use?
Python f-string is faster and more readable than the current string formatting operations. F-strings is also easier to learn since it resembles formatting strings in other languages like C++ or Java.
The f-string operator starts with an ‘f’ character before any of your expressions, i.e., followed by a series of nested expressions surrounded by curly braces { }. You can then list one or two formats side by side, separated by commas. Variables are replaced using curly braces {} instead of percent signs (%).
The expressions inside the curly braces will replace the corresponding parts in your text when executed.
Python f-strings: Example # 01:
Let’s start with one simplest example.
string = 'CodeLeaks'
print(f"{string} is a platform for programming lovers.")
fruit= 'Strawberry'
color= 'Red'
print(f"{fruit} looks delicious in {color} colour.")
Output

Python f-strings: Example # 02
You can work with the datetime Python library with f-string.
import datetime
Date= datetime.datetime.today()
print(f"{Date: %dth %B, %Y}")
name = "Code Leaks"
print(f"{name.lower()} offers easy tutorials.")
Output

Python f-strings: Example # 03
We can perform arithmetic operations in Python f-string.
YourName = "Kathy Charles"
print(f"My friend {YourName} has {4 + 2} feet height.")
Output

Conclusion
Python f-strings are a new feature in Python 3.6 and later used for string interpolation or formatting strings at runtime. They have the potential to simplify your code base with less repetition of expressions that need to be evaluated each time you create a formatted string. You can take advantage of this powerful tool by using it more often in your projects.