Lesson 2 of 12 Β· 9 min Β· 2 hands-on steps

Numbers, Strings & f-strings

Math, text methods and Python's favorite way to build strings.

Python math

Python Β· try it
Loading…

Strings

Python Β· try it
Loading…

f-strings: the Pythonic way to build text

Put an f before the quote and drop values in with { }:

Python Β· try it
Loading…

Watch Python run it

Click Next β–Ά to step through. Watch each variable appear in memory:

Every Python example on this site has a πŸ‘ Step through button too. Use it whenever code surprises you.

πŸ§ͺ Practice: 2 steps

0 / 2 done

Step 1 of 2 Β· Hours and minutes

total_minutes is 135. Use // (whole-number division) and % (remainder) to print exactly:

2 hours and 15 minutes

Python
Loading editor…

Output appears here. Press Run or Ctrl/⌘ + Enter.

βœ… Check your understanding

  1. What is 7 // 2 in Python?

  2. What does f"{2 + 3} apples" produce?

Create a free account to track your progress.