Skip to content

Latest commit

 

History

History
 
 

3-oo-class

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Wednesday - Object Oriented Programming

Before lesson materials

Mandatory:

Advised:

Workshop

Class and Constructor

rectangle1 = {"a": 40, "b": 50}
rectangle2 = {"a": 20, "b": 30}

def get_circumference(rect):
  return rect["a"] * 2 + rect["b"] * 2

print(get_circumference(rectangle1))
print(get_circumference(rectangle2))
class Rectangle():
  a = 0
  b = 0
  
  def __init__(self, a, b):
    self.a = a
    self.b = b

  def get_circumference(self):()
    return self.a * 2 + self.b * 2

rect1 = Rectangle(40, 50)
rect2 = Rectangle(20, 30)
print(rect1.get_circumference())
print(rect2.get_circumference())

01.py 02.py 03.py 04.py 05.py

List functions

my_list = [1, 2, 3]
my_list.append(4)
my_list.pop()

06.py 07.py

Inheritance

class Base():
  a = 0

  def printA(self):
    print("a is:" + str(self.a))

class Child(Base):
  b = 1

  def printB(self):
    print("b is:" + str(self.b))

  def printAll(self):
    self.printA()
    self.printB()

child = Child()
child.a = 12
child.b = 24

08.py

Practice

09.py 10.py 11.py