|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
Tip:
一,理论
二,应用
1
>>> class Try_int(int):
def __add__(self, other):
return self + other
>>> a = Try_int(3)
>>> b = Try_int(2)
>>> a + b
Traceback (most recent call last):
File "<pyshell#34>", line 1, in <module>
a + b
File "<pyshell#30>", line 3, in __add__
return self + other
File "<pyshell#30>", line 3, in __add__
return self + other
File "<pyshell#30>", line 3, in __add__
return self + other
[Previous line repeated 327 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object
2
>>> class Try_int(int):
def __add__(self, other):
return int(self) + int(other) #还是没太理解,为啥转化整形之后就可以出结果,相加的不是方法吗
>>> a = Try_int(3)
>>> b = Try_int(2)
>>> a + b
5
三,课后练习 |
评分
-
查看全部评分
|