PYTHON PROGRAMMING: The ultimate guide from a beginner to expert, all you need to know about python, tools, tricks, best practices, and advanced features by Campbell Clive
Author:Campbell, Clive [Campbell, Clive]
Language: eng
Format: epub
Published: 2019-08-15T16:00:00+00:00
Polymorphism
In Python, polymorphism refers to the ability to use a shared interface for several data types.
Start IDLE.
Navigate to the File menu and click New Window.
Type the following line of code:
class Tilapia:
def swim(self):
print("Tilapia can swim")
def fly(self):
print("Tilapia cannot fly")
class Shark:
def jump(self):
print("Shark can't fly")
def swim(self):
print("Shark can swim")
def jumping_test(fish):
fish.jump()
bonny = Tilapia()
biggy = Shark()
jumping_test(bonny)
jumping_test(biggy)
Explanation
The program above has defined two classes Tilapia and Shark all of which share the method jump() even though they have different functions.
By creating common interface jumping_test() we allowed polymorphism in the program above. We then passed objects bonny and biggy in the jumping_test() function.
Work to do
In a doctor consultation room suggest the class and objects in a programming context.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(12570)
Hello! Python by Anthony Briggs(9915)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9796)
The Mikado Method by Ola Ellnestam Daniel Brolund(9778)
Dependency Injection in .NET by Mark Seemann(9339)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8297)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7696)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7073)
Microservices with Go by Alexander Shuiskov(6839)
Practical Design Patterns for Java Developers by Miroslav Wengner(6760)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6700)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6413)
Angular Projects - Third Edition by Aristeidis Bampakos(6104)
The Art of Crafting User Stories by The Art of Crafting User Stories(5633)
NetSuite for Consultants - Second Edition by Peter Ries(5567)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5373)
Kotlin in Action by Dmitry Jemerov(5062)
