Loading notes...
Loading notes...
Class 11 • Chapter 5
Chapter 5 explains how to manipulate data using Arithmetic, Relational, Logical, and Assignment operators, and how Python evaluates complex expressions using Operator Precedence.
Programs are not just about storing data; they are about manipulating it. Python provides a rich set of Operators—special symbols that carry out arithmetic or logical computations. The values that an operator acts upon are called Operands. When you combine operators and operands, you create an Expression, which Python evaluates down to a single value.
5.1 Arithmetic Operators
Arithmetic operators are used to perform mathematical operations like addition and subtraction.
a = 15
b = 4
print("Float Division:", a / b) # 3.75
print("Floor Division:", a // b) # 3
print("Modulus:", a % b) # 3 (Because 15 = 4*3 + remainder 3)5.2 Relational (Comparison) Operators
Relational operators compare two values. They ALWAYS return a Boolean value (`True` or `False`). These are heavily used in `if` statements.
5.3 Logical Operators
Logical operators are used to combine multiple conditional statements. They also return Booleans.
age = 20
has_license = True
# Using logical operators to combine conditions
can_drive = (age >= 18) and has_license
print("Can they drive?", can_drive) # Output: True5.4 Assignment Operators
The basic assignment operator is `=`. However, Python provides shorthand augmented assignment operators to update variables quickly.
5.5 Operator Precedence (BODMAS for Python)
When an expression has multiple operators (e.g., `5 + 3 * 2`), Python does not just read left to right. It follows strict rules of Precedence. Exponentiation `**` is evaluated first, followed by Multiplication/Division `* / // %`, and finally Addition/Subtraction `+ -`. You can force precedence using Parentheses `()`.