Skip to main content
Anime study buddy

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

Expression

An expression is a combination of values, variables, and operators that evaluates to a result.

Arithmetic operators

+, -, *, /, //, %, **
a, b = 10, 3
print(a + b)
print(a // b)
print(a % b)
print(a ** b)

Relational operators

==, !=, >, <, >=, <=
x = 7
print(x > 5)
print(x == 7)

Logical operators

and, or, not
att = 82
fees = True
print(att >= 75 and fees)

Operator precedence (basic)

  1. ()
  2. **
  3. unary +, -, not
  4. *, /, //, %
  5. +, -
  6. relational operators
  7. and
  8. or
Use parentheses to remove ambiguity.

Exam-focused points

  • / always returns float
  • // is floor division
  • % gives remainder
  • logical operators return boolean result in standard comparisons

Practice questions

  1. Evaluate manually, then verify in Python:
5 + 2 * 3 ** 2
  1. Write expression to check if a number is between 10 and 50.
  2. Write condition for pass: marks >= 40 and attendance >= 75.