self study이성주페이스북 파이썬 그룹2013-05-18
my’self’class LeeSeongjoo:def __init__(self):self.name = u’이성주’self.twitter = ‘@LeeSeongjoo’self.interests = [u‘비디오 얼굴 인식’...
self?class Vector:def __init__(self, x, y):self.x = xself.y = y>>> v = Vector(3, 4)
self? (help!)class Vector:def __init__(self, x, y):self.x = xself.y = y>>> v = Vector(3)TypeError: __init__() takes exactl...
def length(vector):return math.sqrt(vector.x ** 2 + vector.y **2)class Vector:def __init__(self, x, y):self.x = xself.y = ...
def length(vector):return math.sqrt(vector.x ** 2 + vector.y **2)class Vector:def __init__(self, x, y):self.x = xself.y = ...
class Vector:def __init__(self, x, y):self.x = xself.y = ydef length(self):return math.sqrt(self.x ** 2 + self.y **2)>>> v...
globalself ?class Vector:xx = 3yy = 4def __init__(self, x, y):xx = xyy = ydef length(self):return math.sqrt(xx ** 2 + yy *...
self? this?class Vector:def __init__(this, x, y):this.x = xthis.y = ydef length(this):return math.sqrt(this.x ** 2 + this....
>>> sj.say_thank_you()>>> sj.take_questions()>>> sj.exit()
Upcoming SlideShare
Loading in …5
×

파이썬의 Self

1,063 views

Published on

  • Be the first to comment

  • Be the first to like this

파이썬의 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()

×