Methods
Methods are the same as functions but defined
inside the class.

class Time:
def print(self):
print('%.2d:%.2d:%.2d' %
(self.hour, self.minute, self.second)
)
start = Time()
start.hour = 9
start.minute = 45
start.second = 0
Time.print(start)
Active
In OOP, the objects are the
active agents.

class Time:
def set(self, seconds):
time = Time()
minutes, time.seconds = divmod(seconds, 60)
hour, time.minutes = divmod(minutes, 60)
time.hour = hour
return time
def print(self):
print('%.2d:%.2d:%.2d' %
(self.hour, self.minutes, self.seconds)
)
time = Time()
time.set(160).print()
Special methods
Method
__init__ gets invoked when an object is instantiated.

class Time:
def __init__(self, hour=0, min=0, sec=0):
self.hour = hour
self.min = min
self.sec = sec
def __str__(self):
return '%.2d:%.2d:%.2d' % (self.hour, self.min, self.sec)
time = Time(9, 30)
print(time)