SimpleTuts.com

Python F-Strings

An f-string in Python is a formatted string literal that allows you to embed expressions inside curly braces `{}` within the string. It provides a concise and readable way to embed variables and expressions directly into strings.


price = 59
txt = f"The price is {price} dollars"
print(txt)
price = 59
txt = f"The price is {price:.2f} dollars"
print(txt)
txt = f"The price is {20 * 59} dollars"
print(txt)
price = 59
tax = 0.25
txt = f"The price is {price + (price * tax)} dollars"
print(txt)
                
Python Online Compiler