关于调用python自有类报TypeError: __init__() should return None的问题
这几天尝试写了几个python的自有class,在调用的时候,希望能从类中拿到返回一个值。
class classname:
def __init__(self,a,b,c,d):
e=a+b+c+d
return(e)
调用后,编译器报
TypeError: __init__() should return None, not 'int'
网上搜了一下,发现init的写法,不允许返回值,得修改成new
class classname:
def __new__(self,a,b,c,d):
e=a+b+c+d
return(e)
修改后问题解决
浙公网安备 33010602011771号