Learning outcomes
By the end of this chapter, you should be able to:- apply arithmetic operators
- write relational expressions
- evaluate logical expressions
- understand precedence basics
30-minute recording plan
0-8 min: arithmetic operators8-14 min:/vs//and%edge cases14-20 min: relational operators and chained comparisons20-26 min: logical operators (and,or,not)26-30 min: precedence and MCQ output prediction
Expression
An expression is a combination of values, variables, and operators that evaluates to a result.Arithmetic operators
+, -, *, /, //, %, **
/gives decimal (float) output//gives floor result%helps in divisibility checks**is exponent (power)
Beginner alert: / vs //
/ gives exact decimal division, but // gives floor division.
-7 // 3 to be -2, but Python floors downward.
Relational operators
==, !=, >, <, >=, <=
Logical operators
and, or, not
if statements.
MCQ trap: and/or may return operands
In Python, and and or do not always return True/False.
They can return one of the original operands.
Rules:
x and y: returns first falsey operand, otherwise returns last operandx or y: returns first truthy operand, otherwise returns last operand
bool(...), final answer becomes boolean:
Operator precedence (basic)
()**- unary
+,- *,/,//,%+,-- relational operators (
<,<=,>,>=,==,!=,in,not in,is,is not) notandor
3 ** 2->92 * 9->185 + 18->23
Mini showcase: scholarship eligibility check
- relational operators (
>=,<=) - logical
and - grouping with parentheses
Exam-focused points
/always returns float//is floor division%gives remainder- logical operators return boolean result in standard comparisons
- plain
and/orexpressions can return non-boolean operands
Practice questions
- Evaluate manually, then verify in Python:
- Write expression to check if a number is between 10 and 50.
- Write condition for pass: marks >= 40 and attendance >= 75.
- Predict:
