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('') class S1(F1): def show(self)
: print('') class S2(F1): def show(self): print('')
# 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( s1_obj = S1() Func(s1_obj) #
stay Func Function S1 Class s1_obj, implement S1 Of show method , result s2_obj = S2() Func(s2_obj) #
stay Func Function Ss Class ss_obj, implement Ss Of show method , result
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('') class S1(F1): def show(self)
: print('') class S2(F1): def show(self): print('') 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(
s1_obj= S1() Func(s1_obj) s2_obj = S2() Func(s2_obj)
Get more information can be private letter Oh ~~

©2019-2020 Toolsou All rights reserved,
VUE+Canvas Achieve desktop Pinball brick elimination games C/C++ Memory model 2019PHP Interview questions ( Continuously updated )PHPspringboot2 Separation of front and rear platforms ,token Put in header Pit for verification Vue SpringBoot conduct Excel download element-ui Step on pit record 45 The 12-year-old programmer was turned down , Is the workplace wrong ?Python Web frame Pandas Fundamentals of statistical analysis _ data processing (DataFrame Common operations )Java Misunderstanding —— Method overloading is a manifestation of polymorphism ?