+ 13
Python challenge question
Could you guys help me out with this problem, please? The deal is, when I run this code the answer is "False", but I ran into the same question yesterday in a challenge, and the answer was "True"... I don't get it. Comments and suggestions are welcome, thanks y'all! class Solo(): Â x = 0 Â def __str__self(): Â Â self.x += 1 Â Â return str(self.x) a = Solo() print(str(a) == "1" and str(a) == "2")
2 Answers
+ 11
Thanks ChaoticDawg ! Yeah! I finally get it, pal. I overlooked the method names. Gotta have a good eye for this. Thanks, pal!
+ 1
This:
class Solo():
x = 0
def __str__(self):
self.x += 1
return str(self.x)
a = Solo()
print(str(a) == "1" and str(a) == "2")
VS this
class Solo():
x = 0
def __str__self():
self.x += 1
return str(self.x)
a = Solo()
print(str(a) == "1" and str(a) == "2")
First is True, second False
Look at the method names.