반응형
class Foo:
def func1():
print("function 1 is called")
def func2(self):
print(id(self))
print("function 2 is called")
def func3(self):
print(self.__str__)
""" self is instance of class """
foo = Foo()
foo.func2()
print(id(foo))
Foo.func1()
f3 = Foo()
print(f3)
print(id(f3))
print(Foo.func3(f3))
실행결과
$ py self.py
3318160
function 2 is called
3318160
function 1 is called
<__main__.Foo object at 0x0032A298>
3318424
<method-wrapper '__str__' of Foo object at 0x0032A298>
None
반응형
'Programming > Python' 카테고리의 다른 글
Dictionary 데이터에서 키 값만 추출하기 (0) | 2021.04.14 |
---|---|
[Python-Crawling] 정부 혁신 제안 사이트 크롤링 - 1 (0) | 2019.11.07 |
[Python-Basic] Class Data Type - 4(Namespace) (0) | 2019.11.05 |
[Python-Basic] Class Data Type - 3(Inheritance) (0) | 2019.11.05 |
[Python-Basic] Class Data Type - 3(Constructor) (0) | 2019.11.05 |