🌟 Day96 of #100DaysOfPython 🌟

🌟 Day96 of #100DaysOfPython 🌟

Today, we're diving into Object Oriented Programming in python!

What is a class?

A class is a blueprint for creating objects (instances).

It serves as a template that defines the properties and behaviours common to all objects of that type. Essentially, a class encapsulates data (attributes) and functions (methods) that operate on that data.

How do we initialise a class and create instances of the class?

Here, we initialise a class named Employee. This is an empty class with no data or attributes and the pass keyword is used to tell python to skip further execution on this class.

emp_1 & emp_2 are two instances/objects of the class Employee. Both of these instances are unique and have a dedicated memory associated with them.

Instance variables such as first_name, last_name, email, & pay are variables belonging to emp_1 & emp_2 of the Employee() class.

In this demonstration, the instance variables for emp_1 & emp_2 are manually created and does not use the class blueprint. This shows how the the class can be used as a blueprint to create objects.

Q. What method in python helps to create a class as a blueprint that can be used to create objects without repeating instance variables each time when a new instance is created?

To view or add a comment, sign in

Others also viewed

Explore topics