Saturday, 2018-04-21
Stay Close
Site menu
Catalog categories
Computers [3]
Business [3]
Travel [3]
Technology [3]
Sports [3]
Health [3]
Arts [3]
Home & Garden [3]
Entertainment [3]
Tag Board
Our poll
Rate my site
Total of answers: 82
Main » Articles » Computers

How to use inheritance in Python
When scheduling a task with moderate complexity, it is often a good idea to incorporate principles of object-oriented design in the code. The legacy is a principle that can allow the construction and specialized sound code that works out of the codebase. Python supports both individual (a class derived from a class) and multiple (a class derived from many types), inheritance .

Create a base class

Create a base class that your classes resulting call. Make sure your variables and methods are fully functional .

The following is an example of what a class can not inherit: myBaseClass class (object): def myfunc baseVar = 23: print 'Bob Dobbs Slack has' Note that, as the last convention, the definition of a class that does not inherit any user of the packages, we tell the class to the legacy of the Python 'object' class .

Use the Python interpreter to make sure the base class has no syntax errors. You can use a file containing all the class and length: Python myBaseClass.pyIf you do, go back and debug .

use single or multiple

Heritage Heritage Create a class that includes the base class . This is done by writing the name of base class in parentheses at the forefront of its class declaration. Your derived class can use the functions of the base class, and define their own methods. An example might be: Class myDerivedClass (myBaseClass) def derivedFunc: myfunc baseVar print

instance and call the methods of the class derived from outside the class: myDerivedClass.derivedFunc>>> Bob Dobbs has Slack 23

Create a derived class that inherits from several classes, simply listing the kinds of base sequence in parentheses after the class definition, separated by commas: class myDerivedClass (myBaseClass1, myBaseClass2, myBaseClass3): # insert your code class here

This article is written by Writing Articles.

Category: Computers | Added by: hamza (2009-01-15)
Views: 284 | Rating: 0.0/0 |
Total comments: 0
Name *:
Email *:
Code *:
Login form
Search
Site friends
Download StayClose Toolbar

Download StayClose Toolbar

 



( )
Privacy
 
Copyright MyCorp © 2018