Program 15: Find String is a Palindrome or Not - 1000+ Python Programs


Palindrome Check Python Code Example

What is a palindrome?

A palindrome is a string that reads the same forwards and backward.

Example: Hannah, Ava, Ada, Elle, Eve, Anna, Otto, Bob, and Radar.

In this program, we will check if a given string is a palindrome or not.


Pseudo Logic:

1. First, we take the input string from the user.
2. Next we convert the string to lowercase.
3. We then reverse the string and store it in a new variable as reversed_string.
4. We compare the reversed_string  with the original_string.
5. If both strings are the same, then we say that the given string is a palindrome. 
   Otherwise, it is not a palindrome.

Palindrome Python Code

# Python Program no. 15
# Check for Palindrome
# 1000+ Python Programs by Code2care.org

original_string = input("Enter a string: ")
lowercase_string = original_string.lower()
reversed_string = lowercase_string[::-1]

if lowercase_string == reversed_string:
    print(f"The given string {lowercase_string } is a palindrome.")
else:
    print(f"The given string {lowercase_string} is not a palindrome.")
Let's do some testing

Enter a string: Ada
The given string Ada is a palindrome.

Enter a string: Sammual
The given string Sammual is a not palindrome.

Enter a string: Hannah
The given string Hannah is a palindrome.


Python Methods/Concepts used:


Related Alternate Questions:

  1. Write a Python program to check if a given number is a palindrome or not.
  2. Write a Python program to find all the palindromic substrings in a given string.
  3. Write a Python program to find the longest palindrome in a given string.
  4. Write a Python program to check if a given string is an anagram of a palindrome or not.

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright ยฉ Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap