码迷,mamicode.com
首页 > 其他好文 > 详细

练习:字符串的移位

时间:2017-04-10 21:50:11      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:移位   -o   logs   elf   shift   span   pre   代码   log   

要求:

>>> 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]

 

练习:字符串的移位

标签:移位   -o   logs   elf   shift   span   pre   代码   log   

原文地址:http://www.cnblogs.com/marianyad/p/6690698.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!