0
python class
when I run this code in python 3.8, I got True but when I run the same code in python 3.6, I got False.🤣🤣 _______________________________________________ class my_class(): x = 0 def __str__(self): self.x+=1 return str(self.x) a = my_class() print(str(a) == "1" and str(a)=="2") ______________________________________
3 Réponses
+ 1
on sololearn python 3.8.6, output is True as expected ^^
0
visph
Try it in pythontutor visualize tool, it runs python version 3.6
http://pythontutor.com/visualize.html#code=%0A%0A%0Aclass%20my_class%28%29%3A%0A%20%20%20%20x%20%3D%200%0A%20%20%20%20def%20__str__%28self%29%3A%0A%20%20%20%20%20%20%20%20self.x%2B%3D1%0A%20%20%20%20%20%20%20%20return%20str%28self.x%29%0A%0Aa%20%3D%20my_class%28%29%0Aprint%28str%28a%29%20%3D%3D%20%221%22%20and%20str%28a%29%3D%3D%222%22%29%0A&cumulative=false&curInstr=7&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%5D&textReferences=false
0
well, I guess that's not real python wich run your code, but an emulator...
however, they alert about known limitations, and possible bugs ^^
I advise you to contact them and submit the unexpected behavior you're facing, as they advises themselves in the 'known limitations' links...