I. Definition of Class
# Object Oriented # meaningful object-oriented code # class = Object-oriented # Class, Object # instantiation # class The most basic role: encapsulation
class Student (): "' = 0 def print_file (self): print (' Name'+self.name) print('name'+ str (self.age)) Student# instantiation student.print_file ()
Two, the difference between the function and the method
Methods and functions: Design-level functions: a kind of appellation of program running and past style
Third, class and object.
Classes are behaviors and characteristics that describe a class
object is a concrete description object
Class can generate many different objects like a template
Four, the constructor function
#class, ObjectclassStudent (): Name="' Age=0#Behavior and Characteristics def __init__(self):#constructor Function Print('Student') defPrint_file (self):Print('name'+self.name)Print('name'+str (self.age)) s=Student () s.__init__() Student#The constructor is called when the instantiation is instantiatedStudent#The constructor is called separately
The constructor cannot return a value other than none
V. Distinguishing between module variables and variables in a class
Six, class variables and instance variables
Class variables: Variables related to classes
Instance variables: variables associated with an object
classStudent (): Name="' #class VariablesAge =0#Behavior and Characteristics #class variables, instance variables def __init__(self,name,age):#constructor Function #Initialize the properties of an objectSelf.name=name#Defining instance VariablesSelf.age= Age#print (' student ') defPrint_file (self):Print('name'+self.name)Print('name'+str (self.age)) s=student (' Daming', 20)Print(S.name)#to print an instance variable, you need to save the instance variable inside the classPrint (Student.name) #打印类变量
Daming
‘‘
Vii. class and object variable lookup order
Viii. Self and example method
Ix. accessing instance variables and class variables in an instance method
X. Types of methods
Xi. static methods
12. Visibility of Members: public and private
13. Nothing is inaccessible
14, inheritance.
XV, subclass method Call Parent class method: Super keyword
Python (vii) Advanced section: Object-oriented