2019.08.27 learning finishing

2019.08.27 learning finishing

What is inherited

  • Is a new type of way, inherit a class, class attributes and methods in the subclass
  • Parent / base class
  • Subclass / derived class
  • The new class: as long as the inherited object class, the new class is, in python3, the default object class inheritance

-Python3: Default inherit the object
class A:
Pass
the specified object -python2 in succession, to be displayed
- Classic: not inherit object's class, is the classic class
-python3 no Classic
-python2 in only

Use inherited reduce code redundancy

# Inherit a way to reuse the parent class method: Use naming names

Nothing to do with inheritance

# Inherit the parent class method to reuse way: by super keyword

With the inheritance relationship

super () will get a list of the parent object in accordance with mro

The method does not require binding to call objects pass the first parameter (self)

to sum up:

There inheritance, they usually use super,

When naming names the way

  1. No inheritance
  2. If you inherit multiple parent classes, super accordance mro list to find, now want to name names using one of the methods of a parent class, we need to name names of Use

Binding approach

  1. Class to call a bound method object (write functions within the class, did not add decorators), there are a few parameters need several parameters

Generating an object class is instantiated, it will automatically call the initialization operation is completed __init__

Special about binding method of object, would the object itself as the first argument

Diamond inheritance problem

Find new class order and Classic are not the same

Find a new class of property:

Breadth-First

Classic lookup attributes:

Depth-first

Guess you like

Origin www.cnblogs.com/zhangmingyong/p/11419244.html