The so-called polymorphism : The type at definition time is not the same as the type at run time , This is called polymorphism , The concept of polymorphism is applied to Java and C# In this class of strongly typed languages , and Python advocate “ Duck type ”.

Duck type : Although I want one " duck ", But you gave me a bird . But as long as the bird walks like a duck , It sounds like a duck , Swimming is like a duck , I think it's a duck .

Python Polymorphism of , It's the weakening type , The key is whether the object parameters have specified properties and methods , If there is, consider it appropriate , It doesn't care if the object is of the right type .
Python Pseudo code implementation Java or C# Polymorphism of
class F1(object): def show(self): print('F1.show') class S1(F1): def show(self)
: print('S1.show') class S2(F1): def show(self): print('S2.show')
# Because in Java or C# When defining function parameters in , The type of the parameter must be specified # In order to make Func Function can be executed S1 Object show method , It can also be implemented S2 Object show method ,#
So in def Func In the formal parameters of obj What is the type of S1 and S2 The parent of the F1# # The actual parameter passed in is :S1 Objects and S2 object def Func(F1 obj): ""
"Func Function needs to receive a F1 Type or F1 Types of subclasses """ print(obj.show()) s1_obj = S1() Func(s1_obj) #
stay Func Function S1 Class s1_obj, implement S1 Of show method , result :S1.show s2_obj = S2() Func(s2_obj) #
stay Func Function Ss Class ss_obj, implement Ss Of show method , result :S2.show
Let's understand it in a popular way : definition obj This variable is of type :F1 Types of , But in the real call Func Function is not necessarily passed F1 Class , It may be an instance object of its subclass ,
This situation is called polymorphism

Python “ Duck type ”
class F1(object): def show(self): print('F1.show') class S1(F1): def show(self)
: print('S1.show') class S2(F1): def show(self): print('S2.show') def Func(obj):
# python It's a weak type , That is, no matter what is passed ,obj Variables can point to it , There is no polymorphism ( It weakens the concept ) print(obj.show())
s1_obj= S1() Func(s1_obj) s2_obj = S2() Func(s2_obj)
Get more information can be private letter Oh ~~

Technology
©2019-2020 Toolsou All rights reserved,
switch Statement programming : Give a percentage score , Output grade required A,B,C,D,E.Jetson Nano read GPS data (TTL turn USB)yolov3 Detailed explanation - model structure Android Mobile application foundation learning —— Chapter 1 basic introduction Four years of programming , Or is it inferior Database design AWS Elastic Load Balancing (Amazon ELB) Study notes el-select Parameter problem From outsourcing testing to Alibaba , A girl of three books C++STL Container summary