Categories
Python Answers

How to check for palindrome using Python?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *