I am starting to study class
in python, and am trying to get my head around the concepts of attributes
, methods
and parameters
in OOP
.
I am working with 3 examples:
example 1
class Clock(object):
def __init__(self, time):
self.time = time
def print_time(self):
time = '6:30'
print self.time
with:
clock = Clock('5:30')
clock.print_time()
It prints 5:30
example 2
class Clock(object):
def __init__(self, time):
self.time = time
def print_time(self, time):
print time
with:
clock = Clock('5:30')
clock.print_time('10:30')
It prints 10:30
.
example 3
class Clock(object):
def __init__(self, time):
self.time = time
def print_time(self):
print self.time
finally, with:
boston_clock = Clock('5:30')
paris_clock = boston_clock
paris_clock.time = '10:30'
boston_clock.print_time()
It prints 10:30
could please someone explain me how attributes, methods and parameters are being bound to objects in these examples?