Palindrome Checks Done Right
Compare from both ends efficiently.
What Is a Palindrome
A palindrome reads the same forward and backward, like racecar or level. Checking for one is a classic warm-up problem. 🔁
The Slice Trick
Python can reverse a string with the slice s[::-1]. Compare it to the original and you have a one-line check.
s = 'level'
print(s == s[::-1]) # TrueAll lessons in this course
- Characters, ord & chr Tricks
- Count Letters with a Frequency Table
- Palindrome Checks Done Right
- Split, Strip & Rejoin Words