1.1.2 Basic Operators (+ - * / // % **)
Operators are symbols that tell Python how to perform calculations.
Python provides a set of basic arithmetic operators for working with numeric values.
Arithmetic Operators
Python supports the following arithmetic operators:
+: Addition-: Subtraction*: Multiplication/: Division (always returns a float)//: Integer (floor) division%: Modulus (remainder)**: Exponentiation (power)
Operator Behavior
- Division (
/) always produces a floating-point result, even when dividing two integers. - Integer division (
//) discards the decimal part and keeps the integer result. - The modulus operator (
%) is often used to check divisibility. - Exponentiation (
**) is used for power calculations.
Operator Precedence
Python follows a specific order when evaluating expressions:
- Parentheses
() - Exponentiation
** - Multiplication, division, floor division, modulus
- Addition and subtraction
📌 Note:
When expressions become complex, use parentheses to make calculations clearer and safer.