1. Classes and objectsΒΆ
Classes combine data (attributes) and operations (methods) in a structure.
An object is a variable whose type is a class, that is, an object is an instance of a class.
We will only see the basic concepts of object-oriented programming.
When we declare a class, we are creating a new data type.
Just like when we create a list or a string, we are creating instances or creating an instance of these classes.
It is the same to do
list = []
orlist = list()
.The
__init__
method is called constructor and is called when creating the object.The parameter
self
means the television object itself.self.connected
is a value of thetelevision
object.Whenever we want to create attributes of an object, we must associate them with itself using
self
.Otherwise, if we only write
connected = False
,connected
would be just a local variable of the method and not an attribute.