-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass_Practice.py
More file actions
64 lines (47 loc) · 1.6 KB
/
Class_Practice.py
File metadata and controls
64 lines (47 loc) · 1.6 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class BankAccount:
def __init__(self):
self.__balance = 0
def getBalance(self):
return self.__balance
def setBalance(self, balance):
self.__balance = balance
def withdraw(self, amount):
self.__balance -= amount
print("withdraw ", amount, "from your account.")
print("left money: ", self.__balance)
def deposit(self, amount):
self.__balance += amount
print("deposit ", amount, "to account")
print("left money: ", self.__balance)
a = BankAccount()
a.deposit(100)
a.withdraw(100)
# 개채 참조 (개체 비교하기)
class Television:
def __init__(self, channel, volume, on):
self.channel = channel
self.volume = volume
self.on = on
def show(self):
print(self.channel, self.volume, self.on)
def setChannel(self, channel):
self.channel = channel
def getChannel(self):
return self.channel
def setSilentMode(t):
t.volume = 2
myTV =Television(11, 10, True)
setSilentMode(myTV)
myTV.show()
class Person:
def __init__(self, fname, lname) :
self.firstName = fname
self.lastName = lname
class Student(Person):
def __init__(self, fname, lname, year):
super().__init__(fname, lname) # 다른 클래스의 속성 및 메소드를 자동으로 불러와 해당 클래스에서도 사용이 가능하도록 해준다.
self.graduationyear = year
def welcome(self):
print("Welcome", self.firstname, self.lastname, "to the class of", self.graduationyear)
p1 = Student("Kim", "Sanghun", 2024)
p1.welcome()