🎯 By the end of this lesson you can…
- Join and repeat strings
- Use f-strings with expressions
- Format numbers inside f-strings
f-strings: the best way to format
🐍 Python
fstrings.py
👆 Tap a line to explain it
1name = "Meera"2apples = 33price = 12.54print(f"{name} bought {apples} apples.")5print(f"Total: ₹{apples * price}")6print(f"Total: ₹{apples * price:.2f}")7print(f"{'Item':<8}|{'Qty':>4}")8print(f"{'Mango':<8}|{apples:>4}")
Joining and repeating
🐍 Python
joining.py
👆 Tap a line to explain it
1first = "Learn"2second = "With"3print(first + " " + second)4print("🎈" * 5)5print("-" * 20)6print(len("Python"))
🔮 What will this display?
What does this print?
1n = 72print(f"{n} x 3 = {n * 3}")
🛠️ Receipt line
Read an item name, a quantity and a price. Print <qty> x <item> = ₹<total> with the total shown to 2 decimals.
📌 Key takeaways
f"Hi {name}"puts values inside text.f"{price:.2f}"shows exactly 2 decimals."ab" * 3→"ababab".
Finished reading & practising?
Saved in this browser. Create a free account to keep it forever.