-2

I'm trying to compare a string and check if it is palindrome or not. I'm using the next method:

name = input("Enter your string")
name1 = name[-1::-1]
if(name==name1):
    print("True")
else:
    print("False")

but it always shows me False has anyone idea why its not working properly?

1 Answers1

2

Because you are starting at the last character of the string. You want to use name[::-1] instead. That will take the entire string from beginning to end with a step of -1, meaning that it will be reversed.

pzp
  • 6,249
  • 1
  • 26
  • 38
  • I'm printing both cases and get the exact same output, what's wrong? `msj = 'some'; print msj[::-1], msj[-1::-1], msj[::-1]==msj[-1::-1]` --> `emos emos True` – tglaria Dec 22 '15 at 12:58