str='level'
str_rev=''.join(reversed(str))
if(str==str_rev):
print("The string ",str," is a Palindrome ")
else:
print("The string ",str," is NOT a Palindrome ")
Output
The string level is a Palindrome
str='plus2net'
n=len(str) # length of the string
x=''
for i in range(n-1,-1,-1):
#print(str[i],end='')
x=x+str[i]
if(x==str):
print(" \n The string ",str," is a Palindrome ")
else:
print("\n The string ",str," is NOT a Palindrome ")
Output
The string plus2net is NOT a Palindrome
str=input("Enter a string: ")
str_rev=str[::-1]
if(str_rev==str):
print(" \n The string ",str," is a Palindrome ")
else:
print("\n The string ",str," is NOT a Palindrome ")
Output
Enter a string: radar
The string radar is a Palindrome
str=input("Enter any string : ")
x=''
for i in str:
x=i+x
if(x==str):
print(" \n The string ",str," is a Palindrome ")
else:
print("\n The string ",str," is NOT a Palindrome ")
Output
Enter any string : malayalam
The string malayalam is a Palindrome
str=input("Enter a string: ")
str1=str.upper()
str_rev=str1[::-1]
if(str_rev==str1):
print(" \n The string ",str," is a Palindrome ")
else:
print("\n The string ",str," is NOT a Palindrome ")
Output
Enter a string: Radar
The string Radar is a Palindrome
All String methods Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.