我开始在Python中学习class
,并试图让我的头在的attributes
,methods
和parameters
的概念。Python - 类的属性,方法和参数
我与3个例子的工作:
example 1
class Clock(object):
def __init__(self, time):
self.time = time
def print_time(self):
time = '6:30'
print self.time
有:
clock = Clock('5:30')
clock.print_time()
它打印5:30
example 2
class Clock(object):
def __init__(self, time):
self.time = time
def print_time(self, time):
print time
有:
clock = Clock('5:30')
clock.print_time('10:30')
它打印10:30
。
example 3
class Clock(object):
def __init__(self, time):
self.time = time
def print_time(self):
print self.time
最后,用:
boston_clock = Clock('5:30')
paris_clock = boston_clock
paris_clock.time = '10:30'
boston_clock.print_time()
它打印10:30
可以请人解释我是如何的属性,方法和参数被绑定到对象这些例子?
我投票结束这个问题作为题外话,因为这不是一个辅导服务。 – TigerhawkT3
谢谢你的帮助 –
你的问题相当模糊。属性,方法和参数是非常普遍的概念。我认为你需要缩小你需要了解的范围。现在,你甚至不清楚你知道什么属性,方法和参数。这样做可能是很好的做法:“我认为blah是一个参数,并且被绑定到代码行中的某个对象,是正确的吗?”这样人们可以看到你对这些概念的现有理解是什么。 – BrenBarn