1 class Chinese: 2 # create an initialization method, init both sides of the double-underlined. 3 DEF __init__ (Self, Hometown): 4 self.hometown = Hometown 5 Print ( ' Where were you born? ' ) 6 7 DEF Born (Self): 8 Print ( ' I was born in S%. ' % Self.hometown) . 9 10 Xiaoming Chinese = ( ' Guangdong ' ) # pass parameters Hometown . 11 xiaoming.born ()
Initialization process is defined format def __init__(self)
is determined by adding the left and right sides of the init [underscore] bis (the initialize abbreviation "initialization")
The role of the initialization method is that: when each instance of an object is created, the code within the method need not call will automatically run.