Comparison, Logical, Identity Operators in Python

#----------------------------- 1- Comparison Operator ------------------------------- 

value = int(input("Enter the 1st number : "))
val = int(input("Enter the 2nd number : "))

# == Equality operator
print("Equal?")
ans =(value == val)
if ans is True:
    print(ans,"! They are equal.")
if ans is not True:
    print("False! They are different.")
print()
    

# != Not equal operator
print("Not Equal?")

noteq =(value != val)
if noteq is True:
    print("Yes! They are different.")
if noteq is not True:
    print("No! They are same.")

print()

# > Greater than
print("Greater than")

great =(value > val)
if great is True:
    print("Yes! ",value," greater than ",val)
if great is not True:
    print("No! ",val," is greater than ",value)
    
print()

# > Lesser than
print("Lesser than")

less =(value < val)
if less is True:
   print("Yes! ",value," is Lesser than ",val)
if less is not True:
    print("No! ",val," lesser than ",value)
    
    
print()

# >=	Greater than or equal to	
print("Greater than or equal to")

greq =(value >= val)
if greq is True:
   print("Yes! ",value," is greater than or equal to  ",val)
if greq is not True:
    print("No! ",val," is greater or equal than to ",value)
    
    
print()

# <=	lLesser than or equal to	
print("Greater than or equal to")

lseq =(value <= val)
if lseq is True:
   print("Yes! ",value," is lesser than or equal to  ",val)
if lseq is not True:
    print("No! ",val," is lesser or equal than to ",value)
    
    
print()

#----------------------------- 2- Logical Operator ------------------------------- 

value = int(input("Enter the 1st number : "))
val = int(input("Enter the 2nd number : "))

# and operator
# needs two value to compare

print(" A N D")
ans = ((value > -1) and (val > 20))     # returs true only if both are true
print("The answer is ",ans)
print()

# and operator
# needs two value to compare

print(" O R ")
ans = ((value > -1) or (val > 90))     # returs True any of both is True
print("The answer is ",ans)
print()

# not operator
# needs one or  two value to compare

print(" N O T ")   
ans = not((value > -1) and (val > 90)) # returns the reverse value, if True then False #--- if False then True 
no  = (not value > 20 )
print("The answer is ",ans)
print("value is graeter : ",no)
print()

#----------------------------- 3- Identity Operator ------------------------------- 


var = input("Enter the name : ")
var2 = input("Enter the second name : ")

lst = [8,3,5,2,12]
lst2 =[8,3,82,89,121,67,12]


# for values
if var is var2: # returns True if both are same
    print("Both are same.")
elif var is not var2:   #  returns True if both are different
    print("They are different.")
else:
    print()

# for list or tuples
if lst[4] is lst2[6]:   # returns True if both are same
    print("Yes.  Equal")
elif lst is not lst2:   #  returns True if both are different
    print("Yes, They are different..")
else:
    print()

Join our team, where career growth knows no limits.

For More Details

Our internship program guarantees personalized attention for optimal career development in the tech industry.

+91 97879 68375

-> You should bring your own laptop during the internship

Who can apply?

Internships are open for students who: B.E / B.Tech / M.E / M.Tech / B.Sc / M.Sc / M.C.A / B.C.A / Diploma.

  • Ongoing Students Only
  • days, 5days/ 10days or Based on Student Preference
  • Limited 1 to 10 students per slot
  • Registration fees : 1000 INR
  • Slots are filling quickly only fewer slots are available