Two things happened class called stage

``` python

Two things ---- class called phase occurs through knowledge of the errors are summarized as follows: Create an empty object ----- call a class, it will automatically trigger the execution of class __init__ function of the parameter stu1 together incoming. Can be found by the above-mentioned phenomenon, two things happen when the call categories: 1. Create an empty object when called class code is as follows: class OldboyStudent: school = 'oldboy' def choose_course (self): print ( 'is choosing course') stu1 = OldboyStudent () print (stu1 .__ dict__) the result is: {2}, automatically trigger the execution of the class to invoke a class __init__ function, with the incoming call STU1 class and parameters within parentheses. class Oldboy (): school = 'oldboy' def __init __ (self, name, age, gender): # class is called automatically when the trigger __init__ self.name = name self.age = age self.gender = gender print ( ' * '* 50) def choose_course (self): print (' is choosing course ') stu1 = Oldboy (' Joe Smith ', '18', 'female') print (stu1) # print stu1 target print (stu1 .__ dict__) result: { 'name': 'John Doe', 'age': '18', 'gender': 'F'}

```

Guess you like

Origin www.cnblogs.com/ludundun/p/11461569.html