更改实例属性的值

时间:2020-09-02 14:01:16

标签: python class attributes instance

有人知道如何使用30.0更改此矩形的所有边吗?

我尝试了此操作,但结果为“无”:

class Rectangle:

def __init__(self, height=50.0, width=40.0, color="white"):

    self.height = height
    self.width = width
    self.color = color

def area_calculation(self):
    return self.height * self.width

def change_square(self, side):
    self.height = side
    self.width = side

if __name__ == "__main__":
   NewRectangle = Rectangle()
   a=NewRectangle.change_square(30.0)
   print(a)

感谢您的帮助

0 个答案:

没有答案
相关问题