Search⌘ K

Implementing Properties in a Class

Explore how to implement properties within a Python class by creating and initializing attributes like ID, salary, and department. Understand accessing and assigning values using dot notation, and learn the flexibility of adding properties outside the class. This lesson helps you grasp foundational class property concepts crucial for effective object-oriented programming in Python.

In this lesson, we will implement a class named Employee in Python.

Implementation of the Employee class

Let’s implement the Employee class illustrated below. We’ll start with just adding the properties of the class.

With_None
Without_None
# this code will compile
class Employee:
# defining the properties and assigning them none
ID = None
salary = None
department = None

We have defined three properties as class variables ID, ...