+ 3

Can someone explain this??

class Solo(): def __str__(self): return 'sololearn' a='sololearn' b=Solo() print(a==b) #outputs False print(a) #outputs sololearn print(b) #outpots sololearn #then why a==b is False ,please explain

20th Jun 2021, 8:16 AM
Madhava
Madhava - avatar
10 Réponses
+ 11
a != b because they are of different classes. So no matter their content, a == b will be False: https://code.sololearn.com/cNLuQ9PEOeiO/?ref=app
20th Jun 2021, 9:58 AM
Lisa
Lisa - avatar
+ 1
Madhava == checks the reference of the objects
20th Jun 2021, 10:34 AM
Atul [Inactive]
+ 1
Thanks lisa
20th Jun 2021, 1:26 PM
Madhava
Madhava - avatar
+ 1
Thanks Atul
20th Jun 2021, 1:26 PM
Madhava
Madhava - avatar
+ 1
Nak chepava Ra😂
20th Jun 2021, 1:27 PM
Akaza
0
Both are different classes
20th Jun 2021, 12:58 PM
Akaza
0
Thanks ra yesh😅
20th Jun 2021, 1:28 PM
Madhava
Madhava - avatar
0
Good boy 🙂
20th Jun 2021, 1:29 PM
Akaza
0
You should call the function to get the value from it then only it will compare dude 🙌
21st Jun 2021, 3:30 PM
Manish Patel
Manish Patel - avatar
0
Thanks Manish😊
21st Jun 2021, 3:42 PM
Madhava
Madhava - avatar