Python Quest

Track 3 · Lesson 9 of 11

Conditional expressions

Pick between two values in one line with x if condition else y, and know when a full if statement reads better.

About 30 minBeginner4 exercises

You will be able to

  • Write a conditional expression of the form value_if_true if condition else value_if_false
  • Use a conditional expression inside an assignment or an f-string
  • Explain how a conditional expression groups with + and other operators
  • Recognise when a conditional expression hurts readability and rewrite it as an if statement

Included with a Formula Quest membership

It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.

View Formula Quest memberships

Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.