internals

Python string interning

Python string interning Question: While this question doesn’t have any real use in practice, I am curious as to how Python does string interning. I have noticed the following. >>> “string” is “string” True This is as I expected. You can also do this. >>> “strin”+”g” is “string” True And that’s pretty clever! But you …

Total answers: 2

Why can't I add a tuple to a list with the '+' operator in Python?

Why can't I add a tuple to a list with the '+' operator in Python? Question: Python not support adding a tuple to a list: >>> [1,2,3] + (4,5,6) Traceback (most recent call last): File “<stdin>”, line 1, in <module> TypeError: can only concatenate list (not “tuple”) to list What are the disadvantages for providing …

Total answers: 3

Internals of Python list, access and resizing runtimes

Internals of Python list, access and resizing runtimes Question: Is Python’s [] a list or an array? Is the access time of an index O(1) like an array or O(n) like a list? Is appending/resizing O(1) like a list or O(n) like an array, or is it a hybrid that can manage O(1) for accessing …

Total answers: 4

How can I learn more about Python’s internals?

How can I learn more about Python’s internals? Question: I have been programming using Python for slightly more than half an year now and I am more interested in Python internals rather than using Python to develop applications. Currently I am working on porting a few libraries from Python2 to Python3. However, I have a …

Total answers: 6