标准str类型的子类sstr,它实现了“< <”和“>>”方法作为字符串中字符的循环移位。试图做的是python字符串中字符的循环移位
>>> s1 = sstr("abcde")
>>> s1 << 0
'abcde'
>>> s1 >> 0
'abcde'
>>> s1 << 2
'cdeab'
>>> s1 >> 2
'deabc'
>>> s1 >> 5
'abcde'
# my attempt:
import string
class sstr(str):
def __new__(self, other):
return str.__new__(self, other.upper())
def __ilshift__(self, other):
return str.__ilshift(other)
def __rshift__(self, other):
return str.__rshift(other)
我猜这是作业吗? –
本课缺乏作业和日常工作.......... –