All data in Python is stored by reference. (A PyObject*in implementation C). You found that you .split()just returned selfas optimization when the delimiter was not found. When a separator is found, it must create separate string objects for each part, so they are separate objects.
(Unlike Java, which has distinctly different data types for "primitives" and "reference types / classes" and behaves differently with them)
source
share