Simple Inheritance implementation in Python

[1454 views]


In this article, we have demonstrated a simple Python Program which implements Inheritance.

Inheritance example in Python

Code:

class Person: def __init__(self,first,last): self.first_name = first self.last_name = last def name(self): return self.first_name + " " + self.last_name class Employee(Person): def __init__(self,first,last,age): Person.__init__(self,first,last) self.age = age def GetEmployeeDetails(self): return "Name:" + self.name() + " Age:" + self.age if __name__ == '__main__': first = raw_input("Enter your first name") last = raw_input("Enter your last name") age = raw_input("Enter your age") x = Person(first,last) y = Employee(first,last,age) print(x.name()) print(y.GetEmployeeDetails())

Output:

Enter your first name baburao Enter your last name apte Enter your age20 baburao apte Name: baburao apte Age:20
        

Struggling to Understand Algorithm and Flowchart? Try our Notes



Want to Test Your Knowledge on Algorithm and Flowchart?


Other Notes you might be Interested in:




Comments



Search
Recommended Deals End in

Top Java Interview Questions PDF Guide with 30+ Pages



Online Games
Play 2048 Game Online and Relax.
Play 2048 Game Online

Quiz to Test Your Skills
Search Tags