-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdecorator.py
More file actions
47 lines (36 loc) · 1.02 KB
/
decorator.py
File metadata and controls
47 lines (36 loc) · 1.02 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
class Matematika:
@staticmethod
def tambah(a, b):
return a + b
print(Matematika.tambah(1, 2))
class BankAccount:
no = ""
balance = 0
active = True
def __init__(self, no, balance=0):
self.no = no
self.balance = balance
@classmethod
def disabled(cls, no, balance=0):
result = cls(no, balance)
result.active = False
return result
bank_account1 = BankAccount("1234567890", 100000)
bank_account1.balance = -1000
print(f"{bank_account1.no}, {bank_account1.balance}, {bank_account1.active}")
bank_account2 = BankAccount.disabled("1234567890", 100000)
print(f"{bank_account2.no}, {bank_account2.balance}, {bank_account2.active}")
class Category:
__name = ""
@property
def name(self):
return self.__name
@name.setter
def name(self, name):
if name == "":
raise ValueError("Name cannot be empty")
self.__name = name
category1 = Category()
category1.name = "Laptop"
print(category1.name)
print(category1.name)