Skip to content
This repository was archived by the owner on Dec 1, 2022. It is now read-only.

Commit c866821

Browse files
committed
update
1 parent 967b2c5 commit c866821

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# 클래슀 λ©”μ†Œλ“œμ™€ μŠ€νƒœν‹± λ©”μ†Œλ“œ
2+
3+
class Person(object):
4+
5+
kind = 'human'
6+
7+
def __init__(self):
8+
self.x = 100
9+
10+
# 였브젝트λ₯Ό μ•ˆμ¨λ„ λ©”μ†Œλ“œλ₯Ό κ°€μ Έμ˜¬ 수 μžˆλ‹€.
11+
@classmethod
12+
def what_is_your_kind(cls):
13+
return cls.kind
14+
# def what_is_your_kind(self):
15+
#return self.kind
16+
17+
# μ΄λ ‡κ²Œ μ“°λŠ” 것도 κ°€λŠ₯ν•˜λ‹€.
18+
@staticmethod
19+
def about(year):
20+
print('about human {}'.format(year))
21+
22+
# μ˜€λΈŒμ νŠΈκ°€ 좜λ ₯
23+
a = Person()
24+
print(a)
25+
print(a.kind)
26+
print(a.x)
27+
print(a.what_is_your_kind())
28+
29+
print('######################################')
30+
31+
# ν΄λž˜μŠ€κ°€ 좜λ ₯
32+
b = Person
33+
print(b)
34+
print(b.kind)
35+
# print(b.x)
36+
print(b.what_is_your_kind())
37+
38+
print('######################################')
39+
40+
# 였브젝트 없이
41+
print(Person.kind)
42+
print(Person.what_is_your_kind())
43+
Person.about(1999)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# 특수 λ©”μ†Œλ“œλ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€.
2+
3+
class Word(object):
4+
5+
# 이 μƒμ„±μžκ°€ 특수 λ©”μ†Œλ“œλ‹€.
6+
def __init__(self, text):
7+
self.text = text
8+
9+
# λ¬Έμžμ—΄μ„ 읽어왔을 λ•Œ 좜λ ₯ν•˜λŠ” 특수 λ©”μ†Œλ“œμ΄λ‹€.
10+
def __str__(self):
11+
return 'Word!!!!'
12+
13+
# 길이λ₯Ό κ°€μ Έμ˜€λŠ” 특수 λ©”μ†Œλ“œμ΄λ‹€.
14+
def __len__(self):
15+
return len(self.text)
16+
17+
# λ”ν•˜λŠ” 특수 λ©”μ†Œλ“œμ΄λ‹€.
18+
def __add__(self, word):
19+
return self.text.lower() + word.text.lower()
20+
21+
# μž…λ ₯된 값이 μ„œλ‘œ 같은가λ₯Ό νŒλ‹¨ν•˜λŠ” 특수 λ©”μ†Œλ“œμ΄λ‹€.
22+
def __eq__(self, word):
23+
return self.text.lower() == word.text.lower()
24+
25+
w = Word('test')
26+
w2 = Word('##############')
27+
w3 = Word('test')
28+
print(w)
29+
print(len(w))
30+
print(w + w2)
31+
print(w == w2)
32+
print(w == w3)

0 commit comments

Comments
 (0)