Bird
0
0

Why does the expression True and False or True evaluate to True in Python?

hard📝 Conceptual Q10 of 15
Python - Operators and Expression Evaluation
Why does the expression True and False or True evaluate to True in Python?
ABecause both 'and' and 'or' have equal precedence and evaluate simultaneously
BBecause 'or' has higher precedence than 'and', so it evaluates as True and (False or True)
CBecause Python evaluates left to right ignoring precedence
DBecause 'and' has higher precedence than 'or', so it evaluates as (True and False) or True
Step-by-Step Solution
Solution:
  1. Step 1: Recall operator precedence

    'and' has higher precedence than 'or' in Python.
  2. Step 2: Evaluate expression accordingly

    Evaluates as (True and False) or True = False or True = True.
  3. Final Answer:

    Because 'and' has higher precedence than 'or', so it evaluates as (True and False) or True -> Option D
  4. Quick Check:

    Operator precedence: and > or [OK]
Quick Trick: Remember 'and' evaluates before 'or' [OK]
Common Mistakes:
MISTAKES
  • Assuming 'or' evaluates first
  • Ignoring operator precedence
  • Thinking evaluation is left to right only

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes