I was solving the problem at Codesignal and saw one of the solutions that check palindrome like this.
def checkPalindrome(inputString):
return inputString == inputString[::-1]
How is that working? Please explain what is going on here.
I was solving the problem at Codesignal and saw one of the solutions that check palindrome like this.
def checkPalindrome(inputString):
return inputString == inputString[::-1]
How is that working? Please explain what is going on here.
inputString[::-1]
returns the reverse of inputString
. A palindrome is the same word spelled backwards and forwards, and that's what the equality operator checks.