N
N
nonane002342020-04-07 10:24:49
Python
nonane00234, 2020-04-07 10:24:49

Is there polymorphism in dynamically typed languages?

Is there polymorphism in python language?
If so, how is it expressed?

On the example of languages ​​with static typing, it is clear why it is needed.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Shitskov, 2020-04-07
@Zarom

Polymorphism is the ability of objects with the same specification to have different implementations.

Dynamic typing is no good here. And python has abstract classes and inheritance

D
Dmitry, 2020-04-07
@LazyTalent

>>> class SomeClass:
...     def __init__(self, x):
...             self.x = x
...     def __sub__(self, other):
...             return self.x + other.x
... 
>>> sc1 = SomeClass(10)
>>> sc2 = SomeClass(5)
>>> sc1 - sc2
15

M
mayton2019, 2020-04-07
@mayton2019

Polymorphism - refers to the basic features of OOP. That is, the ability to view objects through the prism of the basic interface.
Typing is usually a property of the compiler (or runtime) to determine the type inference of each variable.
These are two different axes of measurements in general. The square is essentially h 4 cells. Whether there is polymorphism or not. And static type or dynamic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question