What is the difference between is operator and == operator?

Questions & AnswersCategory: PythonWhat is the difference between is operator and == operator?
Geek Boy Staff asked 2 years ago

What is the difference between is operator and == operator?

a. There is no difference, these operators can be used interchangeably.
 
b. The == operator is a test for the identity of an object, while is a value comparison. If we use ==, the result will be true if and only if the objects being compared are the same object. If we use is the result will be true every time the values of the compared objects are the same.
 
c. The is operator is a test for the identity of an object, while == is a value comparison. If we use is, the result will be true if and only if the objects being compared are the same object. If we use == the result will be true every time the values of the compared objects are the same.

 

1 Answers
Lokesh Kumar Staff answered 2 years ago

c. The is operator is a test for the identity of an object, while == is a value comparison. If we use is, the result will be true if and only if the objects being compared are the same object. If we use == the result will be true every time the values of the compared objects are the same.