练习:字符串的移位

要求:

>>> a = Nstr(" l love china ")

>>> a >> 6

'china  l love '

>>> a << 3

'love china  l '

 

 

代码:

class Nstr(str):

    def __lshift__(self , other):

        return self[other:] + self[:other]

 

    def __rshift__(self , other):

        return  self[-other:] + self[:-other]

 

posted @ 2017-04-10 20:12  苏阿  阅读(132)  评论(0编辑  收藏  举报