+ 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")

24th Nov 2020, 12:42 AM
Pablo C.
Pablo C. - avatar
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!
24th Nov 2020, 1:03 AM
Pablo C.
Pablo C. - avatar
+ 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.
24th Nov 2020, 12:56 AM
ChaoticDawg
ChaoticDawg - avatar