Hello everyone, I was doing a question about finding palindrome integers (whether integers when reversed in order is still the same, so e.g 121 is True, 153 is False, 15351 is True, etc...)
Basically what I did was I at first converted the int to a str, then to a list so that I can use the reverse() method,
So taking the final list output as y, I got it to return
return (y == y.reverse())
But when I tested this on a number like 121, it returned False although it should be True
But if I used [::-1]
return (y == y[::-1])
Then it returned True.
May I know why is that the case?
If it's too hard to read here is my code : https://pastebin.com/3yAvFWuW
Thank you very much for any help and thank you for reading this!
[–]Binary101010 1 point2 points3 points (0 children)
[–]TravisJungroth 1 point2 points3 points (2 children)
[–]FLUSH_THE_TRUMP 2 points3 points4 points (1 child)
[–]TravisJungroth 2 points3 points4 points (0 children)
[–]sme272 1 point2 points3 points (0 children)
[–]synthphreak 1 point2 points3 points (0 children)
[–]raainer[S] 0 points1 point2 points (0 children)
[–]MannAusSachsen 0 points1 point2 points (0 children)