Upcoming SlideShare
×

파이썬의 Self

734

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
734
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
5
0
Likes
0
Embeds 0
No embeds

No notes for slide

파이썬의 Self

1. 1. self study이성주페이스북 파이썬 그룹2013-05-18
2. 2. my’self’class LeeSeongjoo:def __init__(self):self.name = u’이성주’self.twitter = ‘@LeeSeongjoo’self.interests = [u‘비디오 얼굴 인식’, u’로마 역사’, u’야구’]def feel_about_python(self):print(u’{} 는 파이썬을 좋아합니다.’.format(self.name))def show_current_interests(self):print(‘n’.join(‘{}: {}’.format(*k) for k in enumerate(self.interests)))>>> sj = LeeSeongjoo()
3. 3. self?class Vector:def __init__(self, x, y):self.x = xself.y = y>>> v = Vector(3, 4)
4. 4. self? (help!)class Vector:def __init__(self, x, y):self.x = xself.y = y>>> v = Vector(3)TypeError: __init__() takes exactly 3arguments (2 given)
5. 5. def length(vector):return math.sqrt(vector.x ** 2 + vector.y **2)class Vector:def __init__(self, x, y):self.x = xself.y = y>>> v = Vector(3, 4)>>> length(v)5.0
6. 6. def length(vector):return math.sqrt(vector.x ** 2 + vector.y **2)class Vector:def __init__(self, x, y):self.x = xself.y = y>>> v = Vector(3, 4)>>> v.length = length>>> v.length(v)5.0
7. 7. class Vector:def __init__(self, x, y):self.x = xself.y = ydef length(self):return math.sqrt(self.x ** 2 + self.y **2)>>> v = Vector(3, 4)>>> v.length()5.0
8. 8. globalself ?class Vector:xx = 3yy = 4def __init__(self, x, y):xx = xyy = ydef length(self):return math.sqrt(xx ** 2 + yy **2)>>> v = Vector(5, 12)>>> v.xx3>>> v.yy4>>> v.length()NameError: global name ‘xx’ is not definedxx  3yy  4length__init__xx  3yy  4self.xself.ylength__init__
9. 9. self? this?class Vector:def __init__(this, x, y):this.x = xthis.y = ydef length(this):return math.sqrt(this.x ** 2 + this.y **2)>>> v = Vector(3, 4)>>> v.length()5.0self는 파이썬 객체. 즉, 키워드가 아니다.
10. 10. >>> sj.say_thank_you()>>> sj.take_questions()>>> sj.exit()
1. A particular slide catching your eye?

Clipping is a handy way to collect important slides you want to go back to later.