Hi Guys, welcome to my blog in this article you will learn about how to Write A Program To Create Class Employee With Id And Name And Display Its Contents
Title :
Write A Program To Create Class Employee With Id And Name And Display Its Contents
Description :
Take an employee class and use the default constructor to initialise the ID and the name of an employee.
class Employee:
def __init__(self, id, name):
self.id = id
self.name = name
In the main program take an employee object and all the employee class by passing ID and the name as input to the class constructor. Now using the print function call print the object ID and the object name of the employee as shown below.
employee1 = Employee(1, "Ankita")
print("Employee ID:", employee1.id)
print("Employee Name:", employee1.name)
Complete Python Code :
class Employee:
def __init__(self, id, name):
self.id = id
self.name = name
employee1 = Employee(1, "Ankita")
print("Employee ID:", employee1.id)
print("Employee Name:", employee1.name)
Output :
Employee ID: 1
Employee Name: Ankita
Conclusion :
In the above program employee classes are defined and called using constructor to initialise the class members.
The program takes an object of the employee and uses a print function call to print the name and ID of the employee.
Execute the above Python program by providing random employee name and ID numbers and print the result.
Comment it down below if you have any suggestions to improve the above Python program
0 Comments