Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
Creating a Class Part 2.docx60.8 KB Creating a Class Part 2 - Solution.docx
59.7 KB
Quick reference
Creating a Class Part 2
Let's continue on with classes and fill out our __init__ method.
When to use
Do this virtually every time you create a class.
Instructions
To create an initialization method:
class Employee:
def __init__(self, first_name, last_name):
self.first_name = first_name
self.last_name = last_name
To initialize this class, be sure to pass in the required parameters:
employee_1 = Employee("John", "Elder")
To call out something from this method:
print(employee_1.first_name)
Hints & tips
- In your __init__ method, create variables out of the passed-in parameters
Lesson notes are only available for subscribers.