6. Special Operator:
- Python language offers some special types of operators.
- There are two special operators supports in python.
- Identity Operators
- Membership Operators
6.1 Identity Operators:
is notare the identity operators in Python.
- They are used to check if two values (or variables) are located on the same part of the memory.
- Two equal variables do not imply that they are identical.
- The identity is mainly used for “address comparison”.
- Here, we see that x1 and y1 are integers of the same values, so they are equal as well as identical. Same is the case with x2 and y2 (strings).
- But x3 and y3 are lists. They are equal but not identical. It is because the interpreter locates them separately in memory although they are equal.
6.2 Membership Operators:
not inare the membership operators in Python.
- They are used to test whether a value or variable is found in a sequence (string, list, tuple, set, and dictionary).
Examples: Python is case-sensitive.
Python Operators Precedence
The following table lists all operators from highest precedence to lowest.
|Sr.No.||Operator & Description|
|1||() à Paranthesis ** –> Exponentiation (raise to the power)|
|2||~ + – –> Complement, unary plus, and minus (method names for the last two are +@ and -@)|
|3||* / % // –> Multiply, divide, modulo and floor division|
|4||+ – –> Addition and subtraction|
|5||>> << –> Right and left bitwise shift|
|6||& –> Bitwise ‘AND’|
|7||^ | –> Bitwise exclusive `OR’ and regular `OR’|
|8||<= < > >= –> Comparison operators|
|9||<> == != –> Equality operators|
|10||= %= /= //= -= += *= **= –> Assignment operators|
|11||is is not –> Identity operators|
|12||in not in –> Membership operators|
|13||not or and –> Logical operators|