Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A word that reads the same forwards and backwards is a palindrome. Use a slice to check the words level, python and madam.
A word is a palindrome when it equals its reverse.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Plan. Compare a word with its reverse. The slice word[::-1] is the reverse, and == asks: are they equal?
"level" == "level"[::-1] is True."python" backwards is nohtyp, so it is False."madam" backwards is madam, so it is True.Answer: level and madam are palindromes.
Log in to join the discussion.
Loading…