Arrays
Python doesn't have a fixed-size array type built directly into the core language the way C or Java do. Instead, Python programmers almost always use the built-in list, which can grow, shrink, and hold mixed types. For a stricter, memory-efficient array of a single type, Python offers the array module.
💡 Key insight
In everyday Python code, 'array' almost always means a list — the dedicated array module is used only in specific, performance-sensitive cases.
Syntax
syntax
myList = [value1, value2, value3]
import array
myArray = array.array('i', [1, 2, 3]) # 'i' = integers onlyExample
Python's list works like an array here — indexable, ordered, and iterable — but can also grow or shrink freely.
py
numbers = [10, 20, 30, 40, 50]
for n in numbers:
print(n, end=" ")output10 20 30 40 50
Try it yourself
Copy this example into the Python compiler and run it — try changing a value and see what happens.
