Join my course at Udemy (Python Programming Bible-From beginner to advanced )

Blogger templates

Sunday 9 August 2020

What is the difference between == and IS in python ?

 

==” check for equality of values whereas ‘is’ checks for shared reference.

Just check the following code showing the comparison between the two operators.

In the first part of the above code and as shown in the below figure , variable ‘a’ and ‘b’ is pointing to same string object having the same value “Hello Python” and so both a==b and a is b will return True value.

In the second part of the code and as shown the below diagram, variable ‘a’ and ‘b’ is pointing to different string object having the same value “Hello Python” and so a is b will return False and a==b will return True.

Share:

0 comments:

Post a Comment

Feature Top (Full Width)

Pageviews

Search This Blog