array(typecode [, initializer]) -> array
Return a new array whose items are restricted by typecode, and initialized from the optional initializer value, which must be a list, string. or iterable over elements of the appropriate type.
Arrays represent basic values and behave very much like lists, except the type of objects stored in them is constrained.
Methods:
Attributes:
There are no implemented interfaces.
itemsize
(type: getset_descriptor
)
<attribute 'itemsize' of 'array.array' objects>
typecode
(type: getset_descriptor
)
<attribute 'typecode' of 'array.array' objects>
append(...)
append(x)
Append new value x to the end of the array.
buffer_info(...)
buffer_info() -> (address, length)
Return a tuple (address, length) giving the current memory address and the length in items of the buffer used to hold array's contents The length should be multiplied by the itemsize attribute to calculate the buffer length in bytes.
byteswap(...)
byteswap()
Byteswap all items of the array. If the items in the array are not 1, 2, 4, or 8 bytes in size, RuntimeError is raised.
count(...)
count(x)
Return number of occurences of x in the array.
extend(...)
extend(array or iterable)
Append items to the end of the array.
fromfile(...)
fromfile(f, n)
Read n objects from the file object f and append them to the end of the array. Also called as read.
fromlist(...)
fromlist(list)
Append items to array from list.
fromstring(...)
fromstring(string)
Appends items from the string, interpreting it as an array of machine values,as if it had been read from a file using the fromfile() method).
fromunicode(...)
fromunicode(ustr)
Extends this array with data from the unicode string ustr.
The array must be a type u
array; otherwise a ValueError
is raised. Use array.fromstring(ustr.decode(...)) to
append Unicode data to an array of some other type.
index(...)
index(x)
Return index of first occurence of x in the array.
insert(...)
insert(i,x)
Insert a new item x into the array before position i.
pop(...)
pop([i])
Return the i-th element and delete it from the array. i defaults to -1.
read(...)
fromfile(f, n)
Read n objects from the file object f and append them to the end of the array. Also called as read.
remove(...)
remove(x)
Remove the first occurence of x in the array.
reverse(...)
reverse()
Reverse the order of the items in the array.
tofile(...)
tofile(f)
Write all items (as machine values) to the file object f. Also called as write.
tolist(...)
tolist() -> list
Convert array to an ordinary list with the same items.
tostring(...)
tostring() -> string
Convert the array to an array of machine values and return the string representation.
tounicode(...)
tounicode() -> unicode
Convert the array to a unicode string. The array must be
a type u
array; otherwise a ValueError is raised. Use
array.tostring().decode() to obtain a unicode string from
an array of some other type.
write(...)
tofile(f)
Write all items (as machine values) to the file object f. Also called as write.
There are no known subclasses.