Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Quick recap
Indexing and slicing
10. Negative string indices
Summary

Instruction

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!'
print(text[-1])

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

Exercise

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:

user_question[-1]