Use Equality Operator to Compare the Value of Objects in Python

Mridu Bhatnagar
InstructorMridu Bhatnagar

Share this video with your friends

Send Tweet
Published 4 months ago
Updated 4 months ago

While solving real-life use cases through programming and also while testing your code you will come across scenarios where you have to compare the value of different objects. And, then to solve the problem you can use the equality operator.

Mridu Bhatnagar: [0:02] Compare the objects having equal values using the equality operator. Variable a is assigned to an integer object having value 40. Let us assign variable b to integer object having value 40. Now, we need to compare both the objects. For comparing we'll do a == b.

[0:32] Double equal to is our equality operator. The result that you see is True. The result is true because value of both the objects are same.

[0:50] Now, let us compare the objects having unequal values. Let us assign a variable c to an integer object having value 50. Let us assign a variable d to an integer object having value 60. Then, we can do c == d.

[1:20] Double equal to is our equality operator. When you do Enter, the result now is False. This is so, because both the values of objects were different.