Python Polymorphism | |||
![]() ![]() ![]() | |||
The word "polymorphism" means "many forms", and in programming it refers to methods/functions/operators with the same name that can be executed on many objects or classes. Function Polymorphism An example of a Python function that can be used on different objects is the String For strings
Tuple For tuples
Dictionary For dictionaries
Class Polymorphism Polymorphism is often used in Class methods, where we can have multiple classes with the same method name. For example, say we have three classes:
Look at the for loop at the end. Because of polymorphism we can execute the same method for all three classes. Inheritance Class Polymorphism What about classes with child classes with the same name? Can we use polymorphism there? Yes. If we use the example above and make a parent class called
Child classes inherits the properties and methods from the parent class. In the example above you can see that the The Because of polymorphism we can execute the same method for all classes. Tags: Python Python Polymorphism ![]() ![]() | |||
| |||
| |||
|
SIMILAR POSTSPython ScopePython ModulesPython IteratorsPython InheritancePython Classes/ObjectsPython ArraysPython LambdaPython FunctionsPython While Loops/For LoopsPython Conditions and If statementsPython DictionariesPython SetsPython TuplesPython Comparison OperatorsPython Arithmetic OperatorsPrinting string n timesString concatenation by join()Python ListsPython String OperationsPython Data TypesPython VariablesPython CommentsPython SyntaxPython Getting StartedPython IntroductionWhat is Python?Code Chronicles - A Caffeine-Fueled Journey into Data Software EngineeringMachine Learning Types and Programming LanguagesPython Tutorials for AP Computer Science Principles, Data Projects and High School InternshipMastering Excel Data Manipulation with Python |