Operators in Python are special symbols or keywords used to perform operations on variables and values. Python supports a variety of operators, which can be categorized into different types.
1.) Arithmetic Operators
Arithmetic operators are used to perform mathematical operations such as addition, subtraction, multiplication, and division.
2.) Comparison (Relational) Operators
Comparison operators are used to compare two values and return a Boolean result (True or False).
3.) Logical Operators
Logical operators are used to combine conditional statements.
- Logical AND ( && )
- The AND operator is used to combine two or more conditions, and it returns TRUE if both conditions are true and, if either condition is false, the result will be false.
- Logical OR ( || )
- The OR operator is used to combine two or more conditions, and it returns TRUE if at least one condition is true.
- If at least one condition is true, the result is true; if both are false, the result will be false.
- Logical NOT (!)
- The NOT operator is used to reverse the boolean value of an expression. If the condition is true, it makes it false, and if it is false, it makes it true.
4.) Assignment Operators
Assignment operators are used to assign values to variables.
5.) Bitwise Operators
Bitwise operators work at the binary level (bit-by-bit operation).
6.) Membership Operators
Membership operators are used to check if a value exists in a sequence.
7.) Identity Operators
Identity operators are used to compare the memory location of two objects.