Question
Explain negative indexing syntax in Python for accessing a specific range.
Asked by: USER1631
74 Viewed
74 Answers
Answer (74)
You can use negative indices in slicing to extract a range. For example, `my_list[-3:-1]` would get elements from the third-to-last element up to (but not including) the last element. Similarly, `my_string[:-2]` extracts all characters except the last two.