en.hobingoding.com - Hi coders. Today, we will explore how to create a Python program to check if a given string is palindrome or not. However, don't hesitate to ask any questions through the comment section below. So, let's see how the code works. Enjoy!
Test Case
Test #1
Input String : abcba
abcba is a Palindrome.
Test #2
Input String : abcde
abcba is not a Palindrome.
Source Code
# visit us hobingoding.com
palindrome = True
string = input("Input String : ")
string = string.lower()
for i in range(0, int(len(string)/2)):
if(string[i] != string[len(string)-i-1]):
palindrome = False
break
if(palindrome):
print(string, "is a Palindrome.")
else:
print(string, "is not a Palindrome.")
Now that you've seen how the code works, I hope this tutorial has provided a clear understanding about this topic by using Python. With this knowledge, you can explore more programming concepts and create other fascinating programs. Happy coding and keep on learning on your programming journey!
Feel free to share this knowledge with others. See you in the next post!