Dennis Lee Bieber <wlfr...@ix.netcom.com> writes: > On 2 Nov 2022 09:56:28 GMT, r...@zedat.fu-berlin.de (Stefan Ram) declaimed > the following: > > >> Now, in the next program, I have removed the subclassings, >> there is no inheritance from the base class "Language" >> anymore. Yet the polymorphism in "f" still works. And this >> shows that in Python we do *not* need subclassing/inheritance >> for polymorphism! >> > To me, that is not really an example of polymorphism, but more an > example of Python's "duck typing". > > I'd implement the example hierarchy as > >>>> class Language: > ... def f(self): > ... print(self.greeting) > ... >>>> class English(Language): > ... def __init__(self): > ... self.greeting = "Good Morning" > ... >>>> class French(Language): > ... def __init__(self): > ... self.greeting = "Bonjour" > ... >>>> English().f() > Good Morning >>>> French().f() > Bonjour > > ... with no explicit /function/ for greeting -- it's just an attribute > set in each subtype, inheriting the "f" function for printing.
A popular encyclopedia would enumerate various specifications of the word polymorphism. Ad hoc polymorphism, parametric polymorphim, subtype polymorphim et cetera. ``One of the most difficult matters in all controversy is to distinguish disputes about words from disputes about facts: it ought not to be difficult, but in practice it is.'' -- ABC of Relativity, Bertrand Russell, chapter 12, 1925. ``What's in a name?'' -- Romeo and Juliet, Shakespeare, 1597. -- https://mail.python.org/mailman/listinfo/python-list