inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

허훈님의 게시글

허훈 허훈

@0x6a6f73687561

수강평 작성수
-
평균평점
-

게시글 2

질문&답변

파이썬 (2-2) 같은 오브젝트 참조 관련해서 질문 드립니다.

Python 3.9.0을 사용하고 있습니다. 이게 혹시 버전이 올라가면서 변경된 건 없을까요? iPython을 열고 입력해보면 두 변수의 참조 번호가 다르게 나옵니다(아래는 실행한 결과). 실행환경은 리눅스입니다. joshua@blackwidow:~$ ipython Python 3.9.0 (default, Oct 17 2020, 16:52:55) Type 'copyright', 'credits' or 'license' for more information IPython 7.18.1 -- An enhanced Interactive Python. Type '?' for help. In [1]: m = 800 In [2]: n = 800 In [3]: print(id(m)) 140500560747056 In [4]: print(id(n)) 14050056074689 In [5]: print(id(m), id(n)) 140500560747056 140500560746896 In [6]: 그래서 a=b=c는 혹시 id가 같지 않을까 해서 아래와 같이 해봤더니 이때에는 동일하게 나오네요. joshua@blackwidow:~$ ipython Python 3.9.0 (default, Oct 17 2020, 16:52:55) Type 'copyright', 'credits' or 'license' for more information IPython 7.18.1 -- An enhanced Interactive Python. Type '?' for help. In [1]: a = b = c = 700 In [2]: a is b Out[2]: True In [3]: a is c Out[3]: True In [4]: b is c Out[4]: True In [5]: d = 700 In [6]: a is d Out[6]: False In [7]: print('a: '+str(id(a)), 'b: '+str(id(b)), 'c: '+str(id(c)), 'd: '+str(id(d)), sep='\n') a: 139701311787120 b: 139701311787120 c: 139701311787120 d: 139701311539856 In [8]: a = 701 In [9]: print('a: '+str(id(a)), 'b: '+str(id(b)), 'c: '+str(id(c)), 'd: '+str(id(d)), sep='\n') a: 139701310301872 b: 139701311787120 c: 139701311787120 d: 139701311539856

좋아요수
0
댓글수
2
조회수
293