Yes, if j <= i
is true, the resulting slice is empty, for standard Python types. To get the results in reverse order, you need to add a negative stride:
list[i:j:-1]
because explicit is better than implicit.
This is documented in Common Sequence Operations, footnote 4:
The slice of s from i to j is defined as the sequence of items with index k such that
i <= k < j
. If i or j is greater thanlen(s)
, uselen(s)
. If i is omitted orNone
, use0
. Ifj
is omitted orNone
, uselen(s)
. If i is greater than or equal to j, the slice is empty.
Bold emphasis mine.
Custom types are free to interpret this differently.