|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 dtspsppt 于 2018-9-26 17:10 编辑
这是小甲鱼的代码 :
- class Nstr(str):
- def __lshift__(self,other):
- return self[other:]+self[:other]
- def __rshift__(self,other):
- return self[:-other]+self[-other:]
复制代码
结果是对的
>>> a=Nstr('i love fishc.com!')
>>> a<<3
'ove fishc.com!i l'
>>> a>>3
'i love fishc.com!'
>>>
但是!为什么右移却不能是这样:
- self[-other:]+self[:-other]
复制代码
这是我右移的结果:
>>> a=Nstr('i love fishc.com!')
>>> a<<3
'ove fishc.com!i l'
>>> a>>3
'om!i love fishc.c'
按常理说 i love fishc.com! 左移3次后 是ove fishc.com!i l 没错
但self[:-other]访问的应该是ove fishc.c啊
还有 按照小甲鱼的代码 我上来先>>3 结果不变 这是为啥? |
|