Definition
📌 Arrays
Python doesn't have a fixed-size array type built directly into the core language the way C or Java do.
Syntax
syntax
myList = [value1, value2, value3]
import array
myArray = array.array('i', [1, 2, 3]) # 'i' = integers onlyExample
py
numbers = [10, 20, 30, 40, 50]
for n in numbers:
print(n, end=" ")Output
output10 20 30 40 50
Important Points
- Python's
listis the everyday equivalent of an array — indexed from 0, and resizable. - Lists can hold mixed types (
[1, "two", 3.0]), unlike C/Java arrays. - The dedicated
arraymodule stores only one fixed type, saving memory for large numeric datasets. - For numerical computing at scale, libraries like NumPy provide a true, high-performance array type.
Common Mistakes
- Assuming Python has a fixed-size array by default — the everyday tool is the flexible
list. - Forgetting that list indices, like arrays, start at 0.
- Using a plain list where a NumPy array would be far more efficient for heavy numeric work.
Interview Tip
🎯 Before your interview
Be ready to explain that in interviews, "Python array" questions are usually really about
list — unless the interviewer specifically means NumPy or the array module.
