Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 我是python新手,我试着运行这个花哨的decorators代码_Python 3.x_Pycharm_Decorator - Fatal编程技术网

Python 3.x 我是python新手,我试着运行这个花哨的decorators代码

Python 3.x 我是python新手,我试着运行这个花哨的decorators代码,python-3.x,pycharm,decorator,Python 3.x,Pycharm,Decorator,但是我得到了错误s=Square5 TypeError:Square不带参数,我无法理解它init方法应该有双下划线。将方法更改为uu init__ 参考资料:这是否回答了您的问题? class Square: def _init_(self,side): self._side = side @property def side(self): return self._side @side.setter def side(s

但是我得到了错误s=Square5 TypeError:Square不带参数,我无法理解它

init方法应该有双下划线。将方法更改为uu init__


参考资料:

这是否回答了您的问题?
class Square:
    def _init_(self,side):
        self._side = side
    @property
    def side(self):
        return self._side
    @side.setter
    def side(self,value):
        if value >= 0:
            self._side = value
        else:
            print("error")
    @property
    def area(self):
        return self._side **2
    @classmethod
    def unit_square(cls):
        return cls(1)
s = Square(5)
print(s.side)
print(s.area)
def __init__(self, side):
    self._side = side