鱼C论坛

 找回密码
 立即注册
查看: 1317|回复: 2

[技术交流] 42讲动动手 1 答案有问题

[复制链接]
发表于 2017-3-28 22:33:27 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. class Nstr(str):
  2.     def __lshift__(self, other):
  3.         return self[other:] + self[:other]

  4.     def __rshift__(self, other):
  5.         return self[:-other] + self[-other:]
复制代码


答案代码如上,如果先向右移结果是不变的!!!   如下:

  1. [code]>>> a = Nstr('abcdefg')
  2. >>> a>>3
  3. 'abcdefg'
  4. >>> a<<3
  5. 'defgabc'
复制代码
[/code]

评分

参与人数 1荣誉 +5 鱼币 +5 贡献 +5 收起 理由
小甲鱼 + 5 + 5 + 5 感谢指出!

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-3-28 23:02:32 | 显示全部楼层
的确有问题,这样改一下就可以了。
  1. class Nstr(str):
  2.     def __lshift__(self, other):
  3.         return self[other:] + self[:other]

  4.     def __rshift__(self, other):
  5.         return self[-other:] + self[:-other]
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-3-28 23:05:20 | 显示全部楼层
感谢指出,已经修正答案:

  1. class Nstr(str):
  2.     def __lshift__(self, other):
  3.         return self[other:] + self[:other]

  4.     def __rshift__(self, other):
  5.         return self[-other:] + self[:-other]
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-20 03:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表