Python Glossary Русский

all Python 3arrayterm

array.typecodes

arrays

All type codes array.array accepts on this Python build: a string up to 3.14, a tuple from 3.15.

Syntax

array.typecodes

Checking a code before array.array(code, ...) is easiest with 'd' in array.typecodes: the in operator works for both the string and the tuple. Iteration and len() differ, though: 3.15 added the two-character codes 'Zf' and 'Zd', so the type became a tuple, and len(typecodes) no longer counts the characters of a string. The 'w' code (Py_UCS4) arrived in 3.13 to replace the deprecated 'u'.

Examples

import array
print('d' in array.typecodes, 'x' in array.typecodes)  # → True False
a = array.array('d', [1.5])
print(a.typecode in array.typecodes)  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy