Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

arrays
function
python
communitycreator

What is the array typecode function in Python?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

An array is a collection of multiple items, elements, or values of the same datatype in a single variable.

The typecode() function is used to return the typecode character used to create the array. Typecodes are used for defining arrays in Python. The table below has some of the typecodes in Python.

Type code C type Python type Minimum size in bytes
'b' signed char int 1
'B' unsigned char int 1
'i' signed int int 2
'I' unsigned int int 2
'f' float float 4
'b' double float 8

Parameter value

The typecode() function takes no parameter value.

Return value

The typecode() function returns the typecode character used to create a given array.

Example

# importing the array module
import array as arr
# creating an integer data type array
x = arr.array('i', [1,2,3,4,5,6,7])
# using the typecode funtion to ccheck for the array's typecode
print(x.typecode)

From the output of the code above, the i simply means that the array we created is an integer type.

RELATED TAGS

arrays
function
python
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring