【第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)返回值,数值上是没有差别的但是意义上有什么差别吗?
没有差别
页:
[1]