I was watching a python video, and according to the logic of the slice operator by the instructor, one case was not not working.
step value can be either +ve or -ve
-----------------------------------------
if +ve then it should be forward direction (L to R)
if -ve then it should be backward direction(R to L)
if +ve forward direction from begin to end-1
if -ve backward direction from begin to end + 1
in forward direction
-------------------------------
default : begin : 0
default : end : length of string
default step : 1
in backward direction
---------------------------------
default begin : -1
default end : -(len(string) + 1)
I tried running the satement on python idle and got following result:
>>> x = '0123456789'
>>> x[2:-1:-1]
''
>>> x[2:0:-1]
'21'
According to the rules I should get result as '210'
but I am getting ''
.