Код: Выделить всё
s = 'abcdef'
s[slice(2,4)]
Скажем, я хочу получить элементы со второй до конца, что эквивалентно s[2:]
Код: Выделить всё
s[slice(2)] # only gives first two elements, argument is interpreted as the end of the range
s[slice(2,)] # same as above
s[slice(2, -1)] # gives a range from second to the end excluding the last element
s[slice(2, 0)] # gives empty as expected, since end of range before the start
Подробнее здесь: https://stackoverflow.com/questions/566 ... ice-object