Explore Connect Documentation
Snippets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Point:
  '''Represents a point in a 2-D coordinate space.'''
  num_points = 0
  def __init__(self, x, y):
    Point.num_points += 1
    self.x = x
    self.y = y
  def __del__(self):
    Point.num_points -= 1
    print("destructing a Point object")
    print("{} points left".format(Point.num_points))
class NamedPoint(Point):
  '''Represents a named point in a 2-D coordinate space.'''
  num_points = 0
  def __init__(self, x, y, name):
    # call superclass constructor
    super().__init__(x, y)
    NamedPoint.num_points += 1
    self.name = name
  def __del__(self):
    super().__del__()
    NamedPoint.num_points -= 1
    print("destructing a NamedPoint object")
    print("{} named points left".format(NamedPoint.num_points))
np = NamedPoint(0, 0, "origin point")
print("number of named points:", NamedPoint.num_points)
print("x = {0.x}, y = {0.y}, name = {0.name}".format(np))
Press desired key combination and then press ENTER.