Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>presumably Python has a similar "cache" of such constant strings.

Not really. You're hitting constant folding: https://arpitbhayani.me/blogs/constant-folding-python

This isn't a pre-made list of certain strings that should be cached, this is the compiler noticing that you mentioned the same constant a bunch of times.

Also in general you would see a lot of things with the same id because python uses references all over the place. E.g. assignment never copies.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: