What is polymorphism in Python?
Allows objects to be treated as instances of their parent classes, even when formed from derived classes
It enables the use of an interface with any type of data.
Name the two main mechanisms through which polymorphism is achieved in Python.
These mechanisms allow for flexible and predictable behavior of objects.
What is Duck Typing in Python?
An approach where an object is treated based on its behavior rather than its formal class inheritance
Example: A simple list and a NumPy array can both be iterated over.
True or false: In Python, an object must formally inherit from a related class to be treated polymorphically.
FALSE
Duck Typing allows for behavior-based treatment of objects.
What does Operator Overloading allow in Python?
Empowers objects to behave predictably under standard operations like addition and subtraction
For example, the + operator can perform different operations on integers, floats, and strings.
What is Method Overloading in Python?
Not natively supported, but can be simulated using staticmethod and classmethod decorators
Methods with different parameters but the same name can be associated with their parent class or derived ones.