MCPcopy Create free account
hub / github.com/ZiniuLu/Python-100-Days / Rect

Class Rect

Day01-15/Day08/rect.py:12–34  ·  view source on GitHub ↗

矩形类

Source from the content-addressed store, hash-verified

10
11
12class Rect(object):
13 """矩形类"""
14
15 def __init__(self, width=0, height=0):
16 """构造器"""
17 self.__width = width
18 self.__height = height
19
20 def perimeter(self):
21 """计算周长"""
22 return (self.__width + self.__height) * 2
23
24 def area(self):
25 """计算面积"""
26 return self.__width * self.__height
27
28 def __str__(self):
29 """矩形对象的字符串表达式"""
30 return '矩形[%f,%f]' % (self.__width, self.__height)
31
32 def __del__(self):
33 """析构器"""
34 print('销毁矩形对象')
35
36
37if __name__ == '__main__':

Callers 1

rect.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected