Python For Beginner's Day - 10
contd...
Logical Operators:
used to combine the conditional statements.
| Operator | Description | | --- | --- | | and | Returns True if both statements are true (x < 4 and x < 7) | | or | Returns True if one of the statements is true(x < 4 or x < 7) | | not | Reverse the result, returns False if the result is true |
Identity Operators:
used to compare the objects, if they have same memory location but not with same values.
| Operator | Description | Example | | --- | --- | --- | | is | Returns True if both variables are the same object | x is y | | is not | Returns True if both variables are not the same object | x is not y |
'is' operator
'is not' operator
Membership operator:
used to test if the sequence is present in the object.
| Operator | Description | | --- | --- | | in | Returns True if a sequence with the specified value is present in the object (x in y) | | not in | Returns True if a sequence with the specified value is not present in the object (x not in y) |
Bitwise operator:
used to compare binary numbers.
| Operator | Name | Description | Example | | | --- | --- | --- | --- | --- | | & | AND | Sets each bit to 1 if both bits are 1 | x & y | | | | | OR | Sets each bit to 1 if one of two bits is 1 | x | y | | | ^ | | XOR | Sets each bit to 1 if only one of two bits is 1 | x ^ y | | ~ | NOT | Inverts all the bits | ~x | | | << | Zero fill left shift | Shift left by pushing zeros in from the right and let the leftmost bits fall off | x << 2 | | | \>> | Signed right shift | Shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off | x >> 2 | |
& Operator:
| Operator :
^ Operator :
~ Operator:
<< Operator:
\>> Operator: