Instantiation

Instantiating a class is creating a copy of the class which inherits all class variables and methods. Instantiating a class in Python is simple. To instantiate a class, we simply call the class as if it were a function, passing the arguments that the init method defines. The return value will be the newly created object.

Machine Problem in Python

  1. Create a Class called Employee
  2. Use the init function to collect the employee information
    a. Name, email and mobile number
  3. Instantiate the Employee class two times with different information
  4. Display all the properties of the object.

Program Listing

# mod6_act2.py
# Author : Jake R. Pomperada

class Employee:
    def __init__(self, name, email, mobile):
        self.pangalan = name
        self.email = email
        self.contact = mobile


jp = Employee("Jake Pomperada", "jakerpomperada@gmail.com", "09123612561")
mj = Employee("Michael Jordan", "mj23@gmail.com", "09671722123")

print(f"Name: {jp.pangalan} | Email: {jp.email} | Mobile Number: {jp.contact}")
print(f"Name: {mj.pangalan} | Email: {mj.email} | M

Leave a Reply

Your email address will not be published.