# Python palindrome function; is it possible to write it without using string conversion?

I hope this question is okay to ask on Code Review; this is a little function I wrote in Python 2.7.12 that checks if a number is a palindrome. It works fine but I'd like to know if there is a purely mathematical way to do it without using string conversion.

Here is the function:

def is_palindrome(n):
forward = str(n)
backward = []

i = len(forward) - 1
while i >= 0:
backward.append(forward[i])
i -= 1

backward = "".join(backward)

if backward == forward:
return True
else:
return False


How would one go about solving such a problem without using string conversion?

• divmod(12345, 10)1234, 5 – Gareth Rees Jan 26 '18 at 14:44
• @GarethRees Care to elaborate? – NewbieWanKenobi May 24 '18 at 15:45