Skip to the content

f-strings

Python · Unit 6: Strings

With an f before the quotes, whatever you put between braces {} is swapped for its value.

You no longer need str() or pasting with +.

name = "Maya"
age = 16
print(f"{name}: {age} years")

Prints

Maya: 16 years

The rest of the explanation is in the lesson, which is part of the full plan.

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Predict the output

    What does this code print?

  2. 2. Predict the output

    What does this code print?

  3. 3. Find the bug

    This program should print "Liam: 20". Which line has the error?

  4. 4. Predict the output

    What does this code print?

  5. 5. Complete the code

    Complete it so the function shouts, all in capitals and with a ! at the end.

  6. 6. Multiple choice

    What happens with this code?

  7. 7. Predict the output

    What does this code print?

  8. 8. Predict the output

    What does this code print?

  9. 9. Complete the code

    Complete it to show the tip with two decimals.

  10. 10. Put the lines in order

    The person types how much the bill was and how many people there are. Order it to print how much each one pays.

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →