Character mirror checker
↕ mirror
—
1def is_palindrome(s):
2return s == s[::-1]
Define is_palindrome(s) using string reversal. A perfect example of packaging logic in a named, testable unit.
Same idea as the string lesson, packed in def.
You check whether text reads the same from left to right and right to left.
Used in text validation, puzzle games, bio-sequence checks, and symmetry-related string analysis tasks.
s[::-1] reverses the string — if it equals s, it's a palindrome.True/False and are named is_* or has_* by convention.s.lower() == s.lower()[::-1] for case-insensitive checks.Bioinformatics tools check DNA strand symmetry with palindrome functions. Barcode systems validate symmetric codes. Same concept — a named function called millions of times.