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
1class LuckyLemur():
2 def __init__(self, description):
3 self.description = description
4
5 def reveal_description(self):
6 print(f'Lucky Lemur is {self.description}')
7
8lucky_lemur = LuckyLemur('Pro')
9lucky_lemur.reveal_description()
1class Person:
2 def __init__(self, name, age):
3 self.name = name
4 self.age = age
5
6p1 = Person("John", 36)
7
8p1.age = 40
9
10print(p1.age)
11---------------------------------------------------------------
1240
1
2class Dog(object):
3 def __init__(self, name, age):
4 self.name = name
5 self.age = age
6
7 def speak(self):
8 print("Hi I'm ", self.name, 'and I am', self.age, 'Years Old')
9
10JUB0T = Dog('JUB0T', 55)
11Friend = Dog('Doge', 10)
12JUB0T.speak()
13Friend.speak()