Mandatory:
- https://www.youtube.com/watch?v=POQIIKb1BZA
- https://www.youtube.com/watch?v=G8kS24CtfoI
- https://www.youtube.com/watch?v=qSDiHI1kP98
- https://www.youtube.com/watch?v=oROcVrgz91Y
Advised:
- Hands-on Python Tutorial: Object Orientation (only section 2.1.1)
- Codecademy course - Introduction to Classes
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())
my_list = [1, 2, 3]
my_list.append(4)
my_list.pop()
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