Python Is Palindrome
def / [::-1]Practice

Function: check if a string reads the same backwards

Define is_palindrome(s) using string reversal. A perfect example of packaging logic in a named, testable unit.

Picture this: function wraps the palindrome check

Same idea as the string lesson, packed in def.

sargument
→
s == s[::-1]test
→
return True/Falsebool

In easy words: What is this task?

You check whether text reads the same from left to right and right to left.

Where this is used

Used in text validation, puzzle games, bio-sequence checks, and symmetry-related string analysis tasks.

Theory: string reversal as a boolean function

  • s[::-1] reverses the string — if it equals s, it's a palindrome.
  • Boolean functions return True/False and are named is_* or has_* by convention.
  • Compare s.lower() == s.lower()[::-1] for case-insensitive checks.

Real world: DNA sequences & serial numbers

Bioinformatics tools check DNA strand symmetry with palindrome functions. Barcode systems validate symmetric codes. Same concept — a named function called millions of times.

Character mirror checker

↕ mirror
—
1def is_palindrome(s):
2return s == s[::-1]

Example Program

1def is_palindrome(s): return s == s[::-1]
2print(is_palindrome("racecar"))