Can someone explain this?? | Sololearn: Learn to code for FREE!

+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

6/20/2021 8:16:57 AM

Madhava

10 Answers

New Answer

+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

+1

Madhava == checks the reference of the objects

+1

Thanks lisa

+1

Thanks Atul

+1

Nak chepava Ra๐Ÿ˜‚

0

Both are different classes

0

Thanks ra yesh๐Ÿ˜…

0

Good boy ๐Ÿ™‚

0

You should call the function to get the value from it then only it will compare dude ๐Ÿ™Œ

0

Thanks Manish๐Ÿ˜Š