pablogsal/python-horror-show: Strange and odd python snippets explained
Here you will find a collection of strange and odd python snippets showing apparent odd behavior. The purpose of these scripts is to mess with your head but some people have reported strange new Python knowledge as a secondary effect. From "Integer Objects": The current implementation keeps an array of integer objects for all integers between -5 and 256, when you create an int in that range you actually just get back a reference to the existing object. So it should be possible to change the value of 1. I suspect the behaviour of Python in this case is undefined. :-) We can check this thing using the id operator: The brief explanation is that as in Python everything is an object, each time you use a number (integer, float...) it must be created so this could be very inefficient. So what Python does is pre-allocate integers from -5 to 256 because these are often used. The last trick (a = 300; b = 300) is interpreter-dependent, but in the basic Python interpreter (among others) as the two
Explore this link on the map →saved by
related reading
- Python representation of negative integers - Stack Overflowstackoverflow.com
- PEP 703 – Making the Global Interpreter Lock Optional in CPython | peps.python.orgpeps.python.org
- cpython/Objects/abstract.c at 3.10 · python/cpython · GitHubgithub.com
- 3. Data model — Python 3.14.6 documentationdocs.python.org
- Programming FAQ — Python 3.14.6 documentationdocs.python.org
- Interning (computer science) - Wikipediaen.wikipedia.org
- Python's Array: Working With Numeric Data Efficiently – Real Pythonrealpython.com
- Glossary — Python 3.14.6 documentationdocs.python.org
- PyTorch internals : ezyang's blogblog.ezyang.com
- 9. Classes — Python 3.14.6 documentationdocs.python.org
- Facts and myths about Python names and values | Ned Batcheldernedbatchelder.com
- Built-in Functions — Python 3.14.6 documentationdocs.python.org