How do positive and negative indices behave in relation to each other when dealing with string slicing?

Responsive Ad Header

Question

Grade: Education Subject: Ddos
How do positive and negative indices behave in relation to each other when dealing with string slicing?
Asked by:
103 Viewed 103 Answers
Responsive Ad After Question

Answer (103)

Best Answer
(304)
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.