1# To create a simple class:
2class Shape:
3 def __init__():
4 print("A new shape has been created!")
5 pass
6
7 def get_area(self):
8 pass
9
10# To create a class that uses inheritance and polymorphism
11# from another class:
12class Rectangle(Shape):
13
14 def __init__(self, height, width): # The constructor
15 super.__init__()
16 self.height = height
17 self.width = width
18
19 def get_area(self):
20 return self.height * self.width
21
1A class is a block of code that holds various functions. Because they
2are located inside a class they are named methods but mean the samne
3thing. In addition variables that are stored inside a class are named
4attributes. The point of a class is to call the class later allowing you
5to access as many functions or (methods) as you would like with the same
6class name. These methods are grouped together under one class name due
7to them working in association with eachother in some way.
8
9#example
10# To create a simple class:
11class Shape:
12 def __init__():
13 print("A new shape has been created!")
14 pass
15
16 def get_area(self):
17 pass
18
19# To create a class that uses inheritance and polymorphism
20# from another class:
21class Rectangle(Shape):
22
23 def __init__(self, height, width): # The constructor
24 super.__init__()
25 self.height = height
26 self.width = width
27
28 def get_area(self):
29 return self.height * self.width
1A class is a block of code that holds various functions. Because they
2are located inside a class they are named methods but mean the samne
3thing. In addition variables that are stored inside a class are named
4attributes. The point of a class is to call the class later allowing you
5to access as many functions or (methods) as you would like with the same
6class name. These methods are grouped together under one class name due
7to them working in association with eachother in some way.