Simple Inheritance implementation in Python

(1020 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

Solution Worked 0 UpvotesUpvote

        

Solution Didn't Worked 0 DownvotesDownvote



Comments



Search
Play 2048 Game Online

Search Tags