只是将类型子类化
>>> class X(str):... def my_method(self):... return int(self)...>>> s = X("Hi Mom")>>> s.lower()'hi mom'>>> s.my_method()Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in my_methodValueError: invalid literal for int() with base 10: 'Hi Mom'>>> z = X("271828")>>> z.lower()'271828'>>> z.my_method()271828


