1.

What is the use of negative indices in slicing?

Answer»

Python counts from the end (right) if negative indices are given.

(eg) S = “Hello”

print S[:-3] >> He

print S[-3:] >> llo



Discussion

No Comment Found