-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest32_classvariables.py
More file actions
42 lines (32 loc) · 1 KB
/
test32_classvariables.py
File metadata and controls
42 lines (32 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Employee:
raise_amount = 1.04 # Class variable
num_of_emps = 0
def __init__(self, first, last, pay):
self.first = first
self.last = last
self.pay = pay
self.email = first + '.' + last + '@company.com'
Employee.num_of_emps += 1
def fullname(self):
return f'{self.first} {self.last}'
def apply_raise(self):
#self.pay = int(self.pay * raise_amount) # raise amount is not defined
#self.pay = int(self.pay * Employee.raise_amount) # this works
# or
self.pay = int(self.pay * self.raise_amount)
emp_1 = Employee('me', 'maw', 20000)
emp_2 = Employee('test2', 'noway', 30000)
print(emp_1.pay)
emp_1.apply_raise()
print(emp_1.pay)
Employee.raise_amount = 1.05
print(Employee.raise_amount)
print(emp_1.raise_amount)
print(emp_2.raise_amount)
#print(Employee.__dict__)
emp_1.raise_amount = 1.06
print(Employee.raise_amount)
print(emp_1.raise_amount)
print(emp_2.raise_amount)
print()
print(Employee.num_of_emps)