-4

I have tried reversing a given string and then checking it but want to know the actual method to solve such questions without using any built-in functions of python.

Tried using built-in functions in python but expecting to know the code without using them.

  • 1
    Please clarify what you are asking. You *cannot* do this without builtin functions because strings and numbers *are* builtin and any code handling them must eventually call builtin functions. – MisterMiyagi Dec 19 '22 at 10:30

1 Answers1

-2

You can use list slice for this problem

num = 1234
reverse = int(str(num)[::-1])

if num == reverse:
  print('Palindrome')
else:
  print("Not Palindrome") 

int(str(num[::-1]) is nothing but converting the string format to integer .

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Rakesh
  • 1
  • `some_list[::-1]` is essentially the same as `reversed(some_list)` but clearly less readable. Also, the conversions from and to int do not make sense in the context since OP question is regarding strings. In addition code should be formatted in a code block to improve readability. – wihlke Dec 19 '22 at 14:27