-
Notifications
You must be signed in to change notification settings - Fork 0
/
python_d05_class01.py
68 lines (47 loc) · 1.55 KB
/
python_d05_class01.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
61
62
63
64
65
66
67
68
class It(object):
def __init__(self, company, employee):
self.company = company
self.employee = employee
def __str__(self):
return '{}는 {}명 근무'.format(self.company, self.employee)
#삼성전자 직원 100명 추가
def __add__(self, num): #연산자 중복(magic method)
self.employee = self.employee + num
def __sub__(self, num):
self.employee = self.employee - num
#재정의
def __eq__(self, other):
if self.company == other.company and self.employee == other.employee:
return True
else:
return False
def disp_It(self):
print('{}는 {}명 근무'.format(self.company, self.employee))
def get_company(self):
return self.company
def get_employee(self):
return self.employee
def set_company(self, company):
self.company = company
def set_employee(self, employee):
self.employee = employee
it1 = It('google', 56000)
it2 = It('facebook', 45000)
print(it1)
print(it2)
it1.disp_It()
it2.disp_It()
print(it1.get_company(), '의 직원은', it1.get_employee(), '명')
it1.set_company('삼성전자')
it1.set_employee(96000)
print(it1.get_company(), '의 직원은', it1.get_employee(), '명')
#삼성전자 직원 100명 추가
it1 + 100
it1.disp_It()
it1 - 1500
it1.disp_It()
#위에서 재정의 하지 않았다면 False가 나온다.
it33 = It('facebook', 45000)
it2.disp_It()
it33.disp_It()
print(' == ',it2 == it33)