3 ms·
Those types are wrappers that keep a reference to some data. In any language, it's common to encounter issues when people confuse copying the underlying data wi
by vvillena 4y ago
Those types are wrappers that keep a reference to some data. In any language, it's common to encounter issues when people confuse copying the underlying data with copying just the container around the data and keep pointing to the same thing.
In Python, a list of lists has the same behavior.
l = [ [ 1, 2, 3 ] ]
l2 = l.copy()
l[0][0] = 99
print(l) // [[99,2,3]]
print(l2) // [[99,2,3]]
- itronitron 4y agothere was similar confusion regarding pass by reference and pass by value when Java first came out.