How does python class handle an array when the array is inherited from another class? Does the child class store the array from a parent class as a pointer or does it perform a deep copy and use up extra memory?
For example, if I had a code like
class parentclass(object):
def __init__(self):
self.parentarray = some array
class childclass(object):
def __init__(self,parentclass):
self.childarray = parentclass.parentarray
parent_cls = parentclass()
childclass(parent_cls)
does the program hold two of the same arrays or just one array with one pointer?
Thanks
>Solution :
The general rule in Python is that assignment almost never makes a copy. You just end up with two names to the same array object.
It’s easy to test, if you make a modification to the one array you’ll see the same change in the other.