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
Strings
f-strings: the Pythonic way to build text
Put an f before the quote and drop values in with { }:
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 doneStep 1 of 2 Β· Hours and minutes
total_minutes is 135. Use // (whole-number division) and % (remainder) to print exactly:
2 hours and 15 minutes
Output appears here. Press Run or Ctrl/β + Enter.
Step 2 of 2 Β· Clean up a name
Write clean_name(raw) that removes extra spaces at the start and end and capitalizes each word, so " ada lovelace " becomes "Ada Lovelace".
Output appears here. Press Run or Ctrl/β + Enter.
β Check your understanding
What is 7 // 2 in Python?
What does f"{2 + 3} apples" produce?
Create a free account to track your progress.