【发布时间】:2019-10-08 00:17:45
【问题描述】:
我在看一个python视频,按照导师切片算子的逻辑,有一个case是不行的。
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)
我尝试在 python idle 上运行状态并得到以下结果:
>>> x = '0123456789'
>>> x[2:-1:-1]
''
>>> x[2:0:-1]
'21'
根据规则,我应该得到'210' 的结果,但我得到的是''。
【问题讨论】:
-
请正确格式化您的问题
-
x[2:-len(x)-1:-1]>>>210 -
问题结束后也可以选择答案
标签: python python-3.x