小编fra*_*l21的帖子

如何使用get和set方法创建类?

我想创建一个具有构造函数,带有get和set方法并使用属性的类myCalc。我了解get和set方法,但是在将所有部分组合在一起时遇到了麻烦,因此它可以执行我想要的操作。我到目前为止所拥有的是:

class myCalc(object):

    def __init__(self):
            self._ =name

        def (self):
            """Get the answer doubled."""
            return self._plus

        def (self):
            """Get the answer squared."""
            return self._times
Run Code Online (Sandbox Code Playgroud)

我想让程序响应的对象具有将对象中的数字加倍和平方的属性。任何的意见都将会有帮助。

python methods properties class

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

class ×1

methods ×1

properties ×1

python ×1