We continue to practice programming. After the eighth chapter in the book: Michael Dawson “Programming in Python”, 2014 (Michael Dawson “Python Programming for the Absolute Beginner”, 3rd Edition), where I learned the principles of OOP and program objects / classes, it’s time to move on to practice. Let’s do our homework together!
A Brief Summary of OOP in Python
A program object is a formal representation of a real object in a programming language. Objects are created based on classes.
Basya=Kot() #New object of class Kot
The attributes of an object are its characteristics.
Methods – ways of behavior of the object (~skills of the object).
def hryu(self):
print("Oink, I'm a Kot-class pig!")
method – hryu()
self – параметр
call: Basya.hryu()
Method “Constructor” – called automatically after creating a new object: _init_()
def _init_(self):
print("Oink, I'm a Kot-class pig!")
A class is a part of the code where attributes and methods are declared (~object blueprint). You can create as many objects of the same class (class instances) as you like.
class Kot()
Create multiple class objects:
Basya=Kot()
Siamka=Kot()