R
Rishtaara
Python: Zero to Professional
Lesson 9 of 40Article16 min

Arrays Note, Iterators & Modules

Python lists are the usual dynamic array. For strict numeric arrays, use the array module or NumPy (covered later).

Python Arrays — note

Python lists are the usual dynamic array. For strict numeric arrays, use the array module or NumPy (covered later).

Note: lists handle most everyday array needs in Python.

Real-life example: A Python list is a flexible shelf — hold books, boxes, or both. NumPy is a specialized warehouse for numbers.

List vs array module
# Most code uses lists
nums = [1, 2, 3, 4]

# Strict typed array (optional)
import array
typed = array.array("i", [1, 2, 3])
print(nums, list(typed))

Python Iterators

Iterators produce values one at a time. iter() and next() walk through objects manually.

for loops use iterators under the hood. Classes can define __iter__ and __next__.

Real-life example: An iterator is a PEZ dispenser — one candy at a time until empty.

Manual iteration
values = iter(["a", "b", "c"])
print(next(values))
print(next(values))

Python Modules

Modules are .py files with reusable code. import math, from datetime import date, or import my_helpers.

Split large programs into modules for clarity and testing.

Real-life example: Modules are chapters in a cookbook — import dessert when you need cake, not the whole book at once.

Import patterns
import math
from datetime import date

print(math.sqrt(16))
print(date.today())