Top "Python-internals" questions

How does Python work underneath the hood?

Why is range(0) == range(2, 2, 2) True in Python 3?

Why do ranges which are initialized with different values compare equal to one another in Python 3? When I execute the …

python python-3.x range identity python-internals
Why do tuples take less space in memory than lists?

A tuple takes less memory space in Python: >>> a = (1,2,3) >>> a.__sizeof__() 48 whereas lists takes …

python python-2.7 list tuples python-internals
Why is str.translate much faster in Python 3.5 compared to Python 3.4?

I was trying to remove unwanted characters from a given string using text.translate() in Python 3.4. The minimal code is: …

python string python-3.x python-internals python-3.5
Why is it slower to iterate over a small string than a small list?

I was playing around with timeit and noticed that doing a simple list comprehension over a small string took longer …

python performance cpython timeit python-internals
Python swapping lists

In python, when I assign a list to another, like: a = [1,2,3] b = a Now b and a point to the …

python list iterable-unpacking python-internals
Why are some float < integer comparisons four times slower than others?

When comparing floats to integers, some pairs of values take much longer to be evaluated than other values of a …

python performance floating-point cpython python-internals
Why are assignments not allowed in Python's `lambda` expressions?

This is not a duplicate of Assignment inside lambda expression in Python, i.e., I'm not asking how to trick …

python lambda python-internals side-effects
Is it possible to "hack" Python's print function?

Note: This question is for informational purposes only. I am interested to see how deep into Python's internals it is …

python python-3.x printing python-internals
How exactly is Python Bytecode Run in CPython?

I am trying to understand how Python works (because I use it all the time!). To my understanding, when you …

python cpython python-internals
Why is max slower than sort?

I've found that max is slower than the sort function in Python 2 and 3. Python 2 $ python -m timeit -s 'import random;…

python sorting max python-internals