4.1.11 Formatted Output: f-strings

Unit: Unit 4: Strings, Lists, and Tuples • Interactive Practice

Quick Answer & Summary:

Interactive Python programming tutorial and practice in your browser.

Interactive Challenge (Run Live in Browser):

# Format numeric outputs using modern Python f-strings
item = "Laptop Charger"
price = 49.9
discount_rate = 0.15
discounted_price = price * (1 - discount_rate)

# Format floating-point numbers with 2 decimal places using :.2f
summary = f"Product: {item} | Price: ${discounted_price:.2f}"

print(summary)
Open in Live Interactive Python Sandbox →