Skip to main content

Command Palette

Search for a command to run...

Python의 상수 캐시

Published
1 min readView as Markdown
D
I created SWC, an open-source compiler project, and previously worked at Deno and Vercel. These days, I spend a lot of time building Labor0, along with Watchtower and The AI Platform at Zephyr Cloud IO.

인상적인 파이썬 코드를 봤다.


a = 0.1
b = 0.1

print(a is b) // False


a = 1
b = 1

print(a is b) // True


a = 600000
b = 600000

print(a is b) // False

is는 레퍼런스 비교 연산자이므로, False가 더 정상으로 보인다. 자바에서 비슷한 걸 본 적 있어서 찾아봤더니

What's with the Integer Cache inside Python?

범위는 [-5, 256]

?????

[-5, -1]은 왜 들어간 거지? 나중에 파이썬 이슈 트래커에서 검색해봐야겠다.

More from this blog