반응형

init이 호출되는 시점에 이미 객체(self)가 만들어져 있다

 

dir(인스턴스명) 하면 인스턴스가 가지고 있는 메소드와 속성을 확인할 수 있음

 

>>> dir(my_w)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__','__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'income', 'money', 'now_money', 'owner', 'print_owner_name', 'spend']

 

>>> issubclass(int, object)
True

 

# Method Override(Method를 통째로 다시 씀)

def __init__(self, name, account_no):

    self.account_no = account_no

    #self.owner = name

    #onwer를 지정해주거나 부모클래스의 init을 이용하지 않으면 owner속성을 사용할 수 없음

    super().__init__(name)

 

def __str__(self):

    return '{}의 지갑입니다.'.format(self.owner)

 

>>> print(my_w)
prada의 지갑입니다.

 

def __repr__(self):

    return '{}의 지갑입니다.'.format(self.owner) 

 

>>> my_w
Gucci의 지갑입니다.

반응형

+ Recent posts