-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClasses.py
60 lines (42 loc) · 1.37 KB
/
Classes.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# group data and fn and built on this
# attributes and methods
class Employee:
raise_amount = 1.04
def __init__(self, first, last, pay):
#instead of setting employee deets manually we can use automatic setup using __init__
self.first = first
self.last = last
self.pay = pay
self.email = first.lower() +'.' +last.lower() + '@company.com'
def full_name(self):
return '{} {}'.format(self.first, self.last)
def initials(self):
return '{}{}'.format(self.first[:1], self.last[:1])
def apply_raise(self):
#Lecture 2:
#self.pay = int(self.pay * Employee.raise_amount)
self.pay = int(self.pay * self.raise_amount)
# CLASS vs instance of class
emp_1 = Employee("Corey", "Doe", 50000) #emp_1 is instance of class Employee
emp_2 = Employee("Hey", "Bro", 20) #emp_2 is instance of class Employee
# emp_1.first = 'Corey'
# emp_1.last = 'Doe'
print(emp_2.email) #Doe
#option one for full name
output = emp_2.full_name()
print(output)
#option two for full name
print("Option 2: ",Employee.full_name(emp_2))
initials_emp = emp_1.initials()
print(initials_emp)
print(emp_1.pay)
emp_1.apply_raise()
print(emp_1.pay)
#Lecture 2:
class Whatever:
def __init__(self, val1):
self.val1 = val1
def method1(self):
return self.val1
person1 = Whatever(450)
print(person1.val1)