Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Module « array » Python 3.11.3

Classe « array »

Informations générales

Héritage

builtins.object
    array

Définition

class array(builtins.object):

help(array)

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. The type is specified
at object creation time by using a type code, which is a single character.
The following type codes are defined:

    Type code   C Type             Minimum size in bytes
    'b'         signed integer     1
    'B'         unsigned integer   1
    'u'         Unicode character  2 (see note)
    'h'         signed integer     2
    'H'         unsigned integer   2
    'i'         signed integer     2
    'I'         unsigned integer   2
    'l'         signed integer     4
    'L'         unsigned integer   4
    'q'         signed integer     8 (see note)
    'Q'         unsigned integer   8 (see note)
    'f'         floating point     4
    'd'         floating point     8

NOTE: The 'u' typecode corresponds to Python's unicode character. On
narrow builds this is 2-bytes on wide builds this is 4-bytes.

NOTE: The 'q' and 'Q' type codes are only available if the platform
C compiler used to build Python supports 'long long', or, on Windows,
'__int64'.

Methods:

append() -- append a new item to the end of the array
buffer_info() -- return information giving the current memory info
byteswap() -- byteswap all the items of the array
count() -- return number of occurrences of an object
extend() -- extend array by appending multiple elements from an iterable
fromfile() -- read items from a file object
fromlist() -- append items from the list
frombytes() -- append items from the string
index() -- return index of first occurrence of an object
insert() -- insert a new item into the array at a provided position
pop() -- remove and return item (default last)
remove() -- remove first occurrence of an object
reverse() -- reverse the order of the items in the array
tofile() -- write all items to a file object
tolist() -- return the array converted to an ordinary list
tobytes() -- return the array converted to a string

Attributes:

typecode -- the typecode character used to create the array
itemsize -- the length in bytes of one array item

Constructeur(s)

Signature du constructeur Description
__new__(*args, **kwargs) Create and return a new object. See help(type) for accurate signature. [extrait de __new__.__doc__]
__init__(self, /, *args, **kwargs) Initialize self. See help(type(self)) for accurate signature. [extrait de __init__.__doc__]

Liste des attributs statiques

Nom de l'attribut Valeur
itemsize<attribute 'itemsize' of 'array.array' objects>
typecode<attribute 'typecode' of 'array.array' objects>

Liste des opérateurs

Signature de l'opérateur Description
__add__(self, value) Return self+value. [extrait de __add__.__doc__]
__contains__(self, key) Return key in self. [extrait de __contains__.__doc__]
__delitem__(self, key) Delete self[key]. [extrait de __delitem__.__doc__]
__eq__(self, value) Return self==value. [extrait de __eq__.__doc__]
__ge__(self, value) Return self>=value. [extrait de __ge__.__doc__]
__getitem__(self, key) Return self[key]. [extrait de __getitem__.__doc__]
__gt__(self, value) Return self>value. [extrait de __gt__.__doc__]
__iadd__(self, value) Implement self+=value. [extrait de __iadd__.__doc__]
__imul__(self, value) Implement self*=value. [extrait de __imul__.__doc__]
__le__(self, value) Return self<=value. [extrait de __le__.__doc__]
__lt__(self, value) Return self<value. [extrait de __lt__.__doc__]
__mul__(self, value) Return self*value. [extrait de __mul__.__doc__]
__ne__(self, value) Return self!=value. [extrait de __ne__.__doc__]
__rmul__(self, value) Return value*self. [extrait de __rmul__.__doc__]
__setitem__(self, key, value) Set self[key] to value. [extrait de __setitem__.__doc__]

Liste des méthodes

Toutes les méthodes Méthodes d'instance Méthodes statiques Méthodes dépréciées
Signature de la méthodeDescription
__copy__(self) Return a copy of the array. [extrait de __copy__.__doc__]
__deepcopy__(self, unused) Return a copy of the array. [extrait de __deepcopy__.__doc__]
__getattribute__(self, name) Return getattr(self, name). [extrait de __getattribute__.__doc__]
__iter__(self) Implement iter(self). [extrait de __iter__.__doc__]
__len__(self) Return len(self). [extrait de __len__.__doc__]
__reduce_ex__(self, value) Return state information for pickling. [extrait de __reduce_ex__.__doc__]
__repr__(self) Return repr(self). [extrait de __repr__.__doc__]
__sizeof__(self) Size of the array in memory, in bytes. [extrait de __sizeof__.__doc__]
append(self, v) Append new value v to the end of the array. [extrait de append.__doc__]
buffer_info(self) Return a tuple (address, length) giving the current memory address and the length in items of the buffer used to hold array's contents. [extrait de buffer_info.__doc__]
byteswap(self) Byteswap all items of the array. [extrait de byteswap.__doc__]
count(self, v) Return number of occurrences of v in the array. [extrait de count.__doc__]
extend(self, bb) Append items to the end of the array. [extrait de extend.__doc__]
frombytes(self, buffer) 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. [extrait de frombytes.__doc__]
fromfile(self, f, n) Read n objects from the file object f and append them to the end of the array. [extrait de fromfile.__doc__]
fromlist(self, list) Append items to array from list. [extrait de fromlist.__doc__]
fromunicode(self, ustr) Extends this array with data from the unicode string ustr. [extrait de fromunicode.__doc__]
index(self, v, start=0, stop=9223372036854775807) Return index of first occurrence of v in the array. [extrait de index.__doc__]
insert(self, i, v) Insert a new item v into the array before position i. [extrait de insert.__doc__]
pop(self, i=-1) Return the i-th element and delete it from the array. [extrait de pop.__doc__]
remove(self, v) Remove the first occurrence of v in the array. [extrait de remove.__doc__]
reverse(self) Reverse the order of the items in the array. [extrait de reverse.__doc__]
tobytes(self) Convert the array to an array of machine values and return the bytes representation. [extrait de tobytes.__doc__]
tofile(self, f) Write all items (as machine values) to the file object f. [extrait de tofile.__doc__]
tolist(self) Convert array to an ordinary list with the same items. [extrait de tolist.__doc__]
tounicode(self) Extends this array with data from the unicode string ustr. [extrait de tounicode.__doc__]

Méthodes héritées de la classe object

__delattr__, __dir__, __format__, __getstate__, __hash__, __init_subclass__, __reduce__, __setattr__, __str__, __subclasshook__