程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

The first notes of 2022 Python winter vacation advanced training

編輯:Python
  • class (Class):  A collection of objects with the same properties and methods . It defines the properties and methods that are common to each object in the collection . Object is an instance of a class .
  • Class variables : Class variables are common to the entire instantiated object . Class variables are defined in the class and outside the function body . Class variables are usually not used as instance variables .
  • Data member : Class variable or instance variable , Used to process data related to classes and their instance objects .
  • Method rewriting : If the method inherited from the parent class does not meet the needs of the child class , It can be rewritten , This process is called method coverage (override), Also known as method rewriting .
  • local variable : Variables defined in methods , Class that only works on the current instance .
  • Instance variables : In the declaration of a class , Properties are represented by variables . This variable is called instance variable , It is declared inside the class declaration but outside the other member methods of the class .
  • Inherit : That is, a derived class (derived class) Inherited base class (base class) Fields and methods for . Inheritance also allows the object of a derived class to be treated as a base class object . for example , There is such a design : One Dog Object of type derived from Animal class , This is a simulation " It's a (is-a)" Relationship ( Case diagram ,Dog It's a Animal).
  • Instantiation : Create an instance of a class , Class specific objects .
  • Method : Functions defined in class .
  • object : Data structure instance defined by class . Object contains two data members ( Class variables and instance variables ) And methods .
  •  Example :
    # Create parent class
    class Passengercar(object):
    def __init__(self,name,weight,drive): # Definition __init__ Method
    self.name = name # Pass values to parameters
    self.weight = weight
    self.drive = drive
    def __print__(self): # Define methods Print car Class properties
    print ("Name:",self.name,"Weight : ", self.weight, ", Drive: ", self.drive)
    # Create subclass
    class bus(Passengercar): # Inherited parent class () Inside is the name of the parent class
    def __init__(self,name,weight,drive): # Definition __init__ Method
    super(bus, self).__init__(name,weight,drive) # Inherit the properties of the parent class
    
  • import Demo02 # Test class import
    bus1 = Demo02.bus(" Dongfeng Road 28 Road bus ", "3000kg", " automatic ") # Assign a value to an object
    bus1.__print__() # call print Method 
  • from Demo02 import Class name     # Or import the class directly   
  • If you inherit two parent classes at the same time , Both superclasses have the same method name , Give priority to the methods written in the previous parent class when inheriting .

Such as :from Mother import Mother

       from Father import Father

        class Child(Father,mother):

                def __init__(self,mother,father)

                        Father.__intit__(self,father)

                        Mother.__init__(self,faceValue)

Calling the same named method takes precedence over Father Class method

website :https://www.runoob.com/python/python-object.html Video tutorial ( Study P1\P2\P3):https://www.bilibili.com/video/BV1na4y1x7Si?p=1 polymorphic CSDN:https://blog.csdn.net/weixin_44695969/article/details/92175840

(30 Bar message ) Python How to understand polymorphism in ?_tigerlib The blog of -CSDN Blog _python polymorphic


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved