鱼C论坛

 找回密码
 立即注册
查看: 2176|回复: 0

关于继承的问题(41讲最后一题)

[复制链接]
发表于 2015-6-9 16:50:39 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. class Nint(int):

  2.         def __new__(cls, arg=0):

  3.                 if isinstance(arg, str):

  4.                         total = 0

  5.                         for each in arg:

  6.                                 total += ord(each)

  7.                         arg = total

  8.                 return int.__new__(cls, arg)
复制代码


上面是小甲鱼的代码

下面是我的。


  1. class Mytime(int):
  2.         def __new__(cls,string):
  3.                 total = 0
  4.                 for each in string:
  5.                         total += ord(each)
  6.                 return total
复制代码

用return 返回值 和调用基类__new__有什么区别?对于这道题我实现起来好像没什么问题。。。。
求讲解
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-2-16 11:05

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表