Sometimes, we want to check for palindrome using Python.
In this article, we’ll look at how to check for palindrome using Python.
How to check for palindrome using Python?
To check for palindrome using Python, we can check if the reversed version of the string is the same as the original string.
To do this, we write
is_palindrome = str(n) == str(n)[::-1]
to invert the string n
with str(n)[::-1].
And then we check that the inverted string is the same as n
with ==
.
Conclusion
To check for palindrome using Python, we can check if the reversed version of the string is the same as the original string.