Summer Deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Quick recap
Indexing and slicing
14. Reversing strings
Summary

Instruction

Great! If you use a negative index as the step, you can actually reverse a string! Take a look:

alphabet = 'abcdefghijklmnopqrstuvwyxz'
alphabet[::-1]

The code alphabet[::-1] means "take all characters (with no lower or upper bound) and go back one index at a time." As a result, we'll get a reversed string!

Exercise

Ask the user to provide a palindrome, a word that reads the same backwards and forwards: Write a palindrome:

If the input is an actual palindrome, write: Correct palindrome. Otherwise write: Not a palindrome.

Stuck? Here's a hint!

To check if the user entered a palindrome, use == palindrome[::-1].