Array Class Reference

Defines a true one-dimensional array with a limited number of operations similar those provided in other languages. The elements of the array, which store Python references, can be accessed using normal subscript notation, x[i]. The class is implemented using CPython's hardware array interface.

Public Methods

Array(size)
Creates a one-dimensional array with elements organized in linear order.
Returns the value stored in an element of the array.
Returns the length or number of elements in the array.
Stores a new value into an element of the array.
clear(value)
Clears the array by setting every element to None.

Detailed Description

2.0
Array(size)
Creates a one-dimensional array with elements organized in linear order. The number of elements in the array is provided as an argument and each element is initialized to None. The elements of the array are accessed by index or position with the first element having an index of 0.
Parameter:
size
The number of elements in the array, which must be >= 1.
__len__: len(x)
Returns the length or number of elements in the array.
Returns:
The number of elements in the array.
clear(value)
Clears the array by setting every element to None.
Parameter:
value
The value to be stored in each element of the array.
__getitem__: v = x[index]
Returns the value stored in an element of the array.
Parameter:
index
The index of the element whose value is to be returned. It must be >= 0 and less than the number of elements in the array.
Returns:
The value stored in the given array element.
Exceptions:
IndexError
__setitem__: x[index] = value
Stores a new value into an element of the array. The contents of the array element at position index is changed to value.
Parameters:
index
The index of the element to be changed. It must be >=0 and less than the number of elements in the array.
value
The new value to be stored in the given element.
Exceptions:
IndexError
  August 30, 2026 at 10:46 AM