Question
How do positive and negative indices behave in relation to each other when dealing with string slicing?
Asked by: USER7474
103 Viewed
103 Answers
Responsive Ad After Question
Answer (103)
Positive and negative indices in slicing often 'meet' in the middle of the string. If you have `string[2:-2]`, the positive index 2 starts from the beginning, and the negative index -2 starts from the end. The slicing then effectively extracts a substring excluding the first two and last two characters.