In python ; what is the difference between "is" and "==" ? For example : list1 is list2 ... and list1==list2 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

In python ; what is the difference between "is" and "==" ? For example : list1 is list2 ... and list1==list2

Python syntax

10th May 2019, 2:53 AM
Abdelkader Barraj عبد القادر البراج
Abdelkader Barraj عبد القادر البراج - avatar
5 Answers
+ 5
if you don't override the __eq__ method, == and is give the same result. if you override the methode to define what is the equality (in my code example, p1 equal to p2 if p1.name=p2.name and p1.age=p2.age, in this way you will get different result try this code 😉 https://code.sololearn.com/c7C4L9H7KYHZ/?ref=app
12th May 2019, 5:54 PM
Naiim Khaskhoussi
Naiim Khaskhoussi - avatar
+ 8
hmm, ‘is’ checks if two objects are identical in every way while ‘==‘ checks if both values are the same. Be careful, ‘=‘ is an assigment, different from ‘==‘ 😁
10th May 2019, 3:00 AM
Choe
Choe - avatar
+ 7
"Is" is used for the comparison ( returns true or false) and "=" is used for affection ( for exemple L1=[] L= [1,2,3] L1=L Print (L1) >>> [1,2,3]
10th May 2019, 3:00 AM
Roula Ezzin ( Only Python Challenges )
Roula Ezzin ( Only Python Challenges ) - avatar
+ 6
roula ez femma faute de frappe je l'ai corrigé dans la question ; no9sod difference bin "==" et "is" ; merci comme meme pour le reponse
10th May 2019, 3:44 AM
Abdelkader Barraj عبد القادر البراج
Abdelkader Barraj عبد القادر البراج - avatar
+ 4
Choe thanks for answering ; yes i made a mistake ; i mean the difference between "==" and "is"
10th May 2019, 3:46 AM
Abdelkader Barraj عبد القادر البراج
Abdelkader Barraj عبد القادر البراج - avatar