In this python if else program, we will program to check if any given string is palindrome or not.
A string is a palindrome if it remains the same from both ends. When you reverse a string, it is same as the original string.
Hint:
Use indexing.
Steps to solve the program
- Take a string as input.
- Reverse the given string and store the result in another variable.
- Compare both strings using an if-else statement.
- If both the strings are equal then the string is palindrome, else string is not palinfrome.
- Print the respective output.
str1 = 'jaj'
str2 = str1[::-1]
if str1 == str2:
print("It is a palindrome string")
else:
print("It is not a palindrome string")
Output :
It is a palindrome string
Related Articles
Python program to check whether the given number is positive or not.
Python program to check whether the given number is negative or not.
Python program to check whether the given number is positive or negative and even or odd.
Python program to print the largest number from two numbers.
Python program to check whether a given character is uppercase or not.