实现“<<”和“>>”方法作为字符串中字符的循环移位的标准str类型的子类sstr。尝试做的是
>>> 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)