|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- class Mytuple:
- def __init__(self,*args):
- self.length=0
- self.args=args
- for i in args:
- self.length+=1
- def __len__(self):
- print(self.length)#这里出错了
- def __getitem__(self,key):
- count=0
- for i in self.args:
-
- if count==key:
- return(i)
- count+=1
- m=Mytuple(1,2,3)
- len(m)
复制代码
RESTART: C:/Users/ASUS/AppData/Local/Programs/Python/Python36-32/定制自己的不可变序列.py
3
Traceback (most recent call last):
File "C:/Users/ASUS/AppData/Local/Programs/Python/Python36-32/定制自己的不可变序列.py", line 17, in <module>
len(m)
TypeError: 'NoneType' object cannot be interpreted as an integer
自己不能理解这个错误,请大家帮助
本帖最后由 ba21 于 2017-9-7 09:53 编辑
我也想知道,人家要返回值,你为什么偏偏就不给返回值;而且还莫名的问print不行
- class Mytuple:
- def __init__(self,*args):
- self.length=0
- self.args=args
- for i in args:
- self.length+=1
- def __len__(self):
- print(self.length)#这里出错了
- return self.length#这里出错了
- def __getitem__(self,key):
- count=0
- for i in self.args:
-
- if count==key:
- return(i)
- count+=1
- m=Mytuple(1,2,3)
- len(m)
复制代码
|
|