xiaofan1228 发表于 2020-3-4 11:39:07

【第42讲课后题】关于重写类的返回值

class Nstr(int):
    def __new__(cls, arg=0):
      if isinstance(arg, str):
            total = 0
            for each in arg:
                total += ord(each)
            arg = total
      return int.__new__(cls, arg)#这里去掉上一行的赋值,直接返回 __new__(cls, total)返回值,数值上是没有差别的但是意义上有什么差别吗?

zltzlt 发表于 2020-3-4 11:46:13

没有差别
页: [1]
查看完整版本: 【第42讲课后题】关于重写类的返回值