Introduction To Operators in Python
Introduction To Operators in Python
Operators in Python
Python operators are symbols that perform specific operations on one or more
operands. They are fundamental for writing logical and mathematical expressions
in Python programs. This section provides an overview of the main operator
types and their usage.
by Sajida Soomro
Table of Contents
2.Subtraction (-): Subtracts the second operand from the first. Example: 7 - 4 equals 3.
4.Division (/): Divides the first operand by the second. Example: 10 / 2 equals 5.0.
5.Modulus (%): Returns the remainder of the division of the first operand by the second. Example: 10 % 3 equals 1
6.Exponentiation () or Power Operator**: Raises the first operand to the power of the second. Example: 2 ** 3 equals 8.
Examples
Comparison (Relational) Operators
1 2 3
NOT (not)
Reverses the logical state of its operand. True becomes False, and False becomes True.
Examples
Bitwise Operators
AND (&)
Performs a bitwise AND operation on each pair of corresponding bits.
OR (|)
Performs a bitwise OR operation on each pair of corresponding bits.
Examples
Sajida Soomro