Reputation: 1206
I am testing Python OOP concept of class and instance attributes.
Goal:
Increase the total number of employees (class attribut) each time an instance of the class "Employee" is created.
class Employee:
num_of_emps = 0
raise_amt = 1.04
def __init__(self, first, last, pay):
self.first = first
self.last = last
self.email = first + '.' + last + '@email.com'
self.pay = pay
Employee.num_of_emps =+ 1
emp_1 = Employee('Brian', 'Rigs', 65000)
emp_2 = Employee('Eric', 'Masson', 65000)
emp_3 = Employee('John', 'Doe', 80000)
print(Employee.num_of_emps)
Expected Result: Employee.num_of_emps should be equal to 3
Actual result:
print(Employee.num_of_emps)
1
I should have missed something, any hint?
Upvotes: 0
Views: 97
Reputation: 1668
You just have a minor typo – change Employee.num_of_emps =+ 1
to Employee.num_of_emps += 1
. (I.e. =+
to +=
).
Upvotes: 3