Operators in Python
In Python, operators are symbols that perform operations on variables and values. Here's an overview of the different types of operators in Python:
Arithmetic Operators: Used for basic arithmetic operations.
Addition (+)
Subtraction (-)
Multiplication (*)
Division (/)
Modulus (%)
Exponentiation (**)
Floor division (//)
Comparison (Relational) Operators: Used to compare values.
Equal to (==)
Not equal to (!=)
Greater than (>)
Less than (<)
Greater than or equal to (>=)
Less than or equal to (<=)
Logical Operators: Used to combine conditional statements.
Logical AND (and)
Logical OR (or)
Logical NOT (not)
Assignment Operators: Used to assign values to variables.
Assignment (=)
Add and assign (+=)
Subtract and assign (-=)
Multiply and assign (*=)
Divide and assign (/=)
Modulus and assign (%=)
Exponentiate and assign (**=)
Floor divide and assign (//=)
Identity Operators: Used to compare the memory locations of two objects.
is
is not
Membership Operators: Used to check if a value is present in a sequence (like lists, tuples, or strings).
in
not in
Bitwise Operators: Used to perform bitwise operations on integers.
Bitwise AND (&)
Bitwise OR (|)
Bitwise XOR (^)
Bitwise NOT (~)
Left shift (<<)
Right shift (>>)
These operators are used extensively in Python programming for various tasks like arithmetic calculations, logical operations, comparisons, and more.
Learn more lesson like this: