Tracing the evaluation order

In Python, the variables have the values a = 7, b = 1 and c = False. The program then evaluates the condition below.


Python
not a > 5 or b < 2 and c


With these values every part of the condition is needed. Arrange the operations in the order Python actually performs them at run time, from first to last.

  1. 1.

    Combine the result of b < 2 with c using and

  2. 2.

    Apply not to the result of a > 5

  3. 3.

    Combine the left and right sides using or

  4. 4.

    Evaluate the comparison b < 2

  5. 5.

    Evaluate the comparison a > 5

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Boolean Expressions Questions: