Labs ICT
🎓 SIWES/IT Login

Arrays

1 min read | Python Tutorial
🎓

Doing SIWES / IT attachment?

Get a structured training programme, a supervised digital logbook, and a completion certificate with LabsICT SIWES / IT.

Explore SIWES / IT Training

Python Arrays

The array module provides type-specific arrays that are more memory-efficient than lists when storing homogeneous numeric data. You must specify the type code (e.g., 'i' for signed int, 'f' for float).

Creating an Array

Import the array module and pass a type code and an initial list.

from array import array
nums = array('i', [10, 20, 30, 40, 50])
print(nums)
print(nums[2])

Array Methods

Arrays support similar methods to lists: append(), extend(), insert(), remove(), pop(), reverse().

from array import array
nums = array('f', [1.5, 2.5, 3.5])
nums.append(4.5)
nums.insert(0, 0.5)
nums.pop()
print(nums)