0

Python: a matter of Class()

If b is "sololearn", why result is False? class Solo(): def __str__(self): return "sololearn" a = "sololearn" b = Solo() print (b) print (a==b)

3rd Mar 2020, 7:40 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
2 Respuestas
+ 2
Like HonFu said a and b are two different things. Add this 2 lines of code to see what he means: print(type(a)) print(type(b))
3rd Mar 2020, 7:52 PM
Gabriel Ilie
Gabriel Ilie - avatar
+ 4
b is not the string 'sololearn', b is an instance of the class Solo. When you try to print it, the magic method str returns the string 'sololearn'.
3rd Mar 2020, 7:48 PM
HonFu
HonFu - avatar