Spring Deals - hours only!Up to 70% off on all courses and bundles.-Close
Quick recap
Indexing and slicing
10. Negative string indices


Well done. You already know how to use square brackets to access a given element (e.g., string[3]). Actually, Python has more indexing options. One of them is negative numbers:

text = 'I love Vertabelo!'

Negative indices are used when we want to count backwards. An index of -1 refers to the last character in the string, -2 refers to the second-to-last element, etc. Take a look:

Negative indices


Ask the user to provide a question (i.e., a string with a question mark at the end). Write: Please provide a question in English: If the question is correct, print: Correct question. Otherwise print: Incorrect question.

Stuck? Here's a hint!

To access the last letter, use: