老师这段代码我运行为什么报错。
class Nstr(str):def __lshift__(self, other):
return self+self[:other]
def __rlshift__(self, other):
return self[-other:]+self[:-other]
n = Nstr('abcdefg')
print(n>>2)
print(n<<4)
Traceback (most recent call last):
File "F:/pythonProject/yc042-1.py", line 7, in <module>
print(n>>2)
TypeError: unsupported operand type(s) for >>: 'Nstr' and 'int'
说不支持操作符错误但有时候又可以。谢谢老师解答 rlshift
多了个 l 吧 qiuyouzhi 发表于 2022-3-27 15:39
rlshift
多了个 l 吧
感谢老师。是我粗心了。谢谢
页:
[1]