A palindrome is a word, phrase, number, or sequence of characters that reads the same forward and backward. In other words, it remains unchanged when read from the beginning to the end or from the end to the beginning.
Palindromes are interesting linguistic and numerical constructs that have the same sequence of letters or numbers whether read in the forward or backward direction.
Here are some examples of palindromes:
Words:
"level"
"rotor"
"madam"
"racecar"
"refer"
Phrases:
"Able was I ere I saw Elba."
"Madam, in Eden, I'm Adam."
"A man, a plan, a canal, Panama!"
Numbers:
121
1331
12321
9009
In Python, slicing is a technique used to extract a portion of a sequence (like strings, lists, tuples) by specifying start and end indices. It provides a concise way to access specific parts of a sequence.
The syntax for slicing is sequence[start:stop:step], where:
start: The starting index of the slice (inclusive).
stop: The ending index of the slice (exclusive).
step: Optional. Represents the increment between indices. Default is 1.
Here are some examples: