{"id":33498,"date":"2020-03-17T13:07:07","date_gmt":"2020-03-17T07:37:07","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=33498"},"modified":"2020-03-17T13:07:07","modified_gmt":"2020-03-17T07:37:07","slug":"difference-between-and-is-operator-in-python","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/difference-between-and-is-operator-in-python\/","title":{"rendered":"Difference between == and is operator in Python"},"content":{"rendered":"<p>The == operator compares the values of both the operands and checks for value equality. Whereas is operator checks whether both the operands ask an equivalent object or not.<\/p>\n[pastacode lang=\u201dpython\u201d manual=\u201d%23%20python3%20code%20to%20%20%0A%23%20illustrate%20the%20%20%0A%23%20difference%20between%20%0A%23%20%3D%3D%20and%20is%20operator%20%0A%23%20%5B%5D%20is%20an%20empty%20list%20%0Alist1%20%3D%20%5B%5D%20%0Alist2%20%3D%20%5B%5D%20%0Alist3%3Dlist1%20%0A%20%20%0Aif%20(list1%20%3D%3D%20list2)%3A%20%0A%20%20%20%20print(%22True%22)%20%0Aelse%3A%20%0A%20%20%20%20print(%22False%22)%20%0A%20%20%0Aif%20(list1%20is%20list2)%3A%20%0A%20%20%20%20print(%22True%22)%20%0Aelse%3A%20%0A%20%20%20%20print(%22False%22)%20%0A%20%20%0Aif%20(list1%20is%20list3)%3A%20%0A%20%20%20%20print(%22True%22)%20%0Aelse%3A%20%20%20%20%20%0A%20%20%20%20print(%22False%22)%20\u2033 message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<h3 id=\"output\"><strong>OUTPUT :<\/strong><\/h3>\n[pastacode lang=\u201dpython\u201d manual=\u201dTrue%0AFalse%0ATrue\u201d message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<ul>\n<li>Output of the primary if condition is \u201cTrue\u201d as both list 1 and list 2 are empty lists.<\/li>\n<li>Second if condition shows \u201cFalse\u201d because two empty lists are at different memory locations. Hence list 1 and list 2 ask different objects. we will check it with id () function in python which returns the \u201cidentity\u201d of an object.<\/li>\n<li>Output of the third if condition is \u201cTrue\u201d as both list 1 and list 3 are pointing to an equivalent object.<\/li>\n<\/ul>\n[pastacode lang=\u201dpython\u201d manual=\u201dlist1%20%3D%20%5B%5D%20%0Alist2%20%3D%20%5B%5D%20%0A%20%20%0Aprint(id(list1))%20%0Aprint(id(list2))%20\u2033 message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<h3 id=\"output-2\"><strong>OUTPUT :<\/strong><\/h3>\n[pastacode lang=\u201dpython\u201d manual=\u201d139877155242696%0A139877155253640\u2033 message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The == operator compares the values of both the operands and checks for value equality. Whereas is operator checks whether both the operands ask an equivalent object or not. [pastacode lang=\u201dpython\u201d manual=\u201d%23%20python3%20code%20to%20%20%0A%23%20illustrate%20the%20%20%0A%23%20difference%20between%20%0A%23%20%3D%3D%20and%20is%20operator%20%0A%23%20%5B%5D%20is%20an%20empty%20list%20%0Alist1%20%3D%20%5B%5D%20%0Alist2%20%3D%20%5B%5D%20%0Alist3%3Dlist1%20%0A%20%20%0Aif%20(list1%20%3D%3D%20list2)%3A%20%0A%20%20%20%20print(%22True%22)%20%0Aelse%3A%20%0A%20%20%20%20print(%22False%22)%20%0A%20%20%0Aif%20(list1%20is%20list2)%3A%20%0A%20%20%20%20print(%22True%22)%20%0Aelse%3A%20%0A%20%20%20%20print(%22False%22)%20%0A%20%20%0Aif%20(list1%20is%20list3)%3A%20%0A%20%20%20%20print(%22True%22)%20%0Aelse%3A%20%20%20%20%20%0A%20%20%20%20print(%22False%22)%20\u2033 message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/] OUTPUT : [pastacode lang=\u201dpython\u201d manual=\u201dTrue%0AFalse%0ATrue\u201d message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/] Output of the primary if condition is \u201cTrue\u201d as both list 1 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":33508,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[86902,86901,86886],"class_list":["post-33498","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding","tag-conditions-methods-in-python","tag-different-operators-in-python","tag-operators-in-python"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/33498","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=33498"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/33498\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media\/33508"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=33498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=33498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=33498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}