filmov
tv
Check If a Word is a Palindrome in Python Using One Line! 🚀

Показать описание
Want to check if a word is a palindrome in just one line of Python code? In this short video, I’ll show you how to use Python’s slice method [::-1] to check if a word reads the same forward and backward!
🔹 Code Used in the Video:
def check_palindrome(s):
if s == s[::-1]:
print("It is a palindrome!")
else:
print("It is not a palindrome!")
check_palindrome("radar") # It is a palindrome!
check_palindrome("hello") # It is not a palindrome!
Try it out with your own words and comment your favorite palindrome! 🔥
💡 Don't forget to Like, Share & Follow for more Python tips! 🚀
🔹 Code Used in the Video:
def check_palindrome(s):
if s == s[::-1]:
print("It is a palindrome!")
else:
print("It is not a palindrome!")
check_palindrome("radar") # It is a palindrome!
check_palindrome("hello") # It is not a palindrome!
Try it out with your own words and comment your favorite palindrome! 🔥
💡 Don't forget to Like, Share & Follow for more Python tips! 🚀