类和对象

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了类和对象相关的知识,希望对你有一定的参考价值。

类和对象

 1 class Rectangle:
 2     length = 5
 3     width = 4
 4 
 5     def getRect(self):
 6         print(矩形的长是:%.2f,宽是:%.2f%(self.length, self.width))
 7 
 8     def setRect(self):
 9         print 请输入长和宽
10         self.length = float(input(长:))
11         self.width = float(input(宽:))
12 
13     def getArea(self):
14         print(矩形的面积是:%.2f%(self.length*self.width))
15 
16 rect = Rectangle()

 

以上是关于类和对象的主要内容,如果未能解决你的问题,请参考以下文章