Python basic class daily finishing (Fri)

Source: Internet
Author: User

03_ Object-oriented _day01

  1. An object-oriented abbreviation?
    Object-oriented programming--object oriented programming shorthand OOP, is a programming idea or method
  2. Object-oriented and process-oriented differences?
    Process-oriented is an early programming idea, all steps are realized from beginning to end, and some functional independent blocks of code are encapsulated into functions, then the different functions are called in order, the steps and processes are paid attention, and the responsibility Division is not emphasized, which is suitable for developing simple projects.
    Object-oriented functions are a larger package, object-oriented objects and responsibilities, different objects take on different responsibilities, and are suitable for developing more complex projects.
  3. The concept of classes and objects?
    Classes and objects are the two core concepts of object-oriented,
    A class is a generic term for a group of things that have the same characteristics or behavior, which is abstract and cannot be used directly. Like a drawing or a template, you can create many objects based on this template.
    An object is a concrete existence created by a class and can be used directly.
  4. Class and object relationships?
    Class is a template, objects are created from the template of the class, there should be classes first, and then there are objects
    The class has only one, and the object can have many, and the properties between different objects may vary
    What properties and methods are defined in the class, what properties and methods are in the object, not much, or less
  5. What are the properties and methods?
    A characteristic description of an object, which can usually be defined as a property
    An object has a behavior (verb) that can usually be defined as a method
  6. How do I define a class and create an object?
    Class Name:
    Def Method 1 (Self, argument list):
    Pass
    The class name conforms to the large hump name, and the first parameter of the method must be self,self, which represents the object that is currently calling the method itself within the method and can pass self. You can access the properties of an object, or through self. Calling other object methods
    Create an object as follows:
    Object variable = class name () automatically allocates memory space, auto-Initialize method (define attribute)
  7. Init () The role of the method
    The initialization method, which is automatically executed when the object is created, is used primarily to define the properties of the class
  8. Str () The role of the method
    Returns the description information of the object, the print function outputs the object variable, the ability to plot the custom content, must return a string
  9. del () The role of the method
    object is automatically called before it is destroyed from memory
  10. Three main features of object-oriented
    Encapsulation, inheritance, polymorphism
  11. How do you understand object-oriented encapsulation?
    The first step in object-oriented programming is to encapsulate the properties and methods into a class, the outside world uses classes to create objects, and then let the object invoke methods, and the details of the object methods are encapsulated inside the class.
    03_ Object-oriented _day02
  12. Private properties, private methods, pseudo-private properties, and methods
    Private property: The property that the object does not want to expose, and the syntax is to precede the property with the property name
    Private method: The method that the object does not want to expose, and the syntax is
    to precede the method with the method name
    Pseudo-private properties and methods refer to the fact that there is no real private in python, but that the attribute or method name is preceded by the _ Class name, which can be accessed through the Class name __ property name, but is not recommended.
  13. The role of inheritance, as well as the syntax
    Inheritance implements the reuse of code, which can have all the methods and properties of the parent class.
    Class Subclass name (parent class name):
    Pass
    Inheritance is transitive, and subclasses can have all of the parent class methods and properties that have an inheritance relationship with the child class.
  14. Overriding the parent class method, how to invoke the overridden parent class method?
    You can override a method when the method implementation of the parent class does not meet the subclass requirements (override)
    There are two cases of overriding a parent class method:
    Overrides a method of the parent class in which a method with the same name as the parent class is created;
    Extend the parent class method, using super (). The parent class method call, which can also be accessed through the parent class name. Parent class method (), but not recommended.
  15. The concept of multiple inheritance and syntax
    Multiple inheritance: Subclasses can have more than one parent class and have properties and methods for all the parent classes. Methods and properties with the same name should be avoided as much as possible between multiple parent classes.
    Class Subclass name (parent class Name 1, parent class Name 2 ...)
    Pass
  16. The concept of polymorphism.
    Different subclass objects call the same parent class method, resulting in different execution results
    Polymorphism can increase the flexibility of the code to inherit and rewrite the parent class method as a precondition, is the technique of invoking the method, does not affect the class's internal design

Python basic class daily finishing (Fri)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.