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
1class Person:#set name of class to call it
2 def __init__(self, name, age):#func set ver
3 self.name = name#set name
4 self.age = age#set age
5
6
7 def myfunc(self):#func inside of class
8 print("Hello my name is " + self.name)# code that the func dose
9
10p1 = Person("barry", 50)# setting a ver fo rthe class
11p1.myfunc() #call the func and whitch ver you want it to be with
1#NOTES
2class PartyAnimal:
3 def Party():
4 #blahblah
5
6an=PartyAnimal()
7
8an.Party()# this is same as 'PartyAnimal.Party(an)'
1class ClassName:
2 self.attribute_1 = variable_1 #Set attributes for all object instances
3 self.attrubute_2 = variable_2
4
5 def __init__(self, attribute_3, attribute_4): #Set attributes at object creation
6 self.attribute_3 = attribute_3
7 self.attribute_4 = attribute_4
8
9 def method(self): #All methods should include self
10 print("This is a method example.") #Define methods just like functions
11
12
13object = Object(4, "string") #Set attribute_3 and attribute_4
14object.method() #Methods are called like this.