Python Identity Operators | If not | not in | is not | is | Tutorial with Examples

By Digamber Rawat Last updated on
I am going to share with you Python Identity Operators | in | not in | is not | is | tutorial with examples. Operators in python are used to validate the value of a programme, Operator in Python checks the value in a list, tuples and string.

The if not Operator in Python Example

#Python not in operator example

a = 15

if not a > 15:
    print("True")
else:
    print("False")

# Output: True    

Python not in Example

The not in operator can be used with if statement, and if the vale is False, then it will return True.

In this Python not in example we are declaring 2 variables a and b, we created myArray in the array we defined some numbers and by using if not in example with if statement in Python we are checking whether a and b variables value available in the array.

Result:

The is not Python operator Example

The Python is not operator returns false if the expressions on either side are indicating towards the same object if not then it will return true. Check out the example below.

# Python 'is not' operator 

a = 7.3

if (type(a) is not int): 
    print ("True") 
else: 
    print ("False") 

#Output: True

Python is not Operator Demo

The is Python operator Example

The Python is operator returns true if the expressions on either of the side is indicating towards the same object if not, then it will return false. Check out the example below.

# Python 'is' identity operator 

a = 9

if (type(a) is int): 
    print ("True") 
else: 
    print ("False") 

# Output: True

Digamber Rawat
Digamber Rawat

Full stack developer with a passion for UI/UX design. I create beautiful and useful digital products to solve people’s problem and make their life easy.

Hire Me