我是python的新手,我想知道__init__(self,Name1,Name2,...)
的目的是什么 在类内。
它是类实例的初始值设定项。 self 引用对象本身,而 Name1、Name2 等是初始值设定项的输入参数。
class Thingy(object):
def __init__(self, color):
self.color = color
x = Thingy('red')
print x.color
'red'