What are Python's comparison and logical operators?
Why Interviewers Ask This
This is a classic screening question for Python roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.
Answer
Python comparison operators return booleans: == (equal), != (not equal), <, >, <=, >=. Python supports chained comparisons: 0 < x < 10 (equivalent to 0 < x and x < 10). Logical operators: and, or, not. Python uses short-circuit evaluation: a and b returns a if a is falsy, otherwise b. a or b returns a if truthy, otherwise b. This enables Pythonic patterns: name = input_name or "default". Identity operators: is, is not. Membership operators: in, not in — check membership in sequences, dicts (by key), and sets. Bitwise operators: &, |, ^, ~, <<, >>.
Common Mistake
Many candidates answer correctly but can't explain the 'why'. Always be prepared to justify your answer with a concrete example or use case from your Python experience.