-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path(0802)CandyDemo.py
More file actions
49 lines (33 loc) · 1.11 KB
/
(0802)CandyDemo.py
File metadata and controls
49 lines (33 loc) · 1.11 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
43
44
45
46
47
48
49
#class Candy:
# def set_info(self, shape, color):
# self.shape = shape
# self.color = color
class Candy():
def __init__(self, shape, color): # 더블언더바(던더라고 부름) init == 생성자
self.shape = shape
self.color = color
#satang = Candy()
#satang.set_info('circle', 'brown')
satang = Candy('circle', 'brown') # 객체에 넣고 메소드를 사용하는걸 한번에 가능케함
print(satang.shape)
print(satang.color)
class Sample():
def __del__(self): # 소멸자. 별로 안써서 몰라도 됨
print('has been closed')
sample = Sample()
del sample # 객체가 자동으로 삭제됨
class USB:
def __init__(self, capacity):
self.capacity = capacity
def info(self):
print('{}GB USB'.format(self.capacity))
usb = USB(64)
usb.info()
class Service():
def __init__(self,service):
self.service = service
print('{}service가 시작되었습니다.'.format(self.service))
def __del__(self):
print('{}service가 종료되었습니다.'.format(self.service))
s = Service('길 안내')
del s