def append(self, ele):
Add element to end of the array
if self.n == self.capacity:
self.A[self.n] = ele
self.n += 1
1. The parameter object
will be stored in the array
. If the value of
is greater than the number of elements of
then an exception will be thrown.
2. The value of
is increased by
, in order to point to the next free element in the array
B = self.make_array(new_cap)
for k in range(self.n):
B[k] = self.A[k]
self.A = B
self.capacity = new_cap
Returns a new array with new_cap capacity
return (new_cap * ctypes.py_object)()
1. Set the reference
to point to the newly created array
. So all references will access the data in the new array.
2. Set the variable
to the value of the parameter
. That is just replacing one value in a variable with another (similar to i = 5).
3. The method
is creating a new raw array that can hold up to
objects. The array reference is then passed back to the caller of the method, as referred to in lines 1 and 2.
See also The Python Tutorial — Python 3.7.2 documentation