I built a simple leave request app for a small U.S. team after our HR person kept tracking time off in a messy Excel sheet. I wanted a local Python tool that ten employees across Dallas, Chicago, and Seattle could use from the command line, with approved requests saved permanently in SQLite. Along the way, I had to create arrays in Python constantly, just to hold names and dates before anything touched the database.
This guide covers the methods I used: list, list comprehensions, the array module, and NumPy arrays. Each has a purpose, and picking the right one makes your code faster and cleaner. All examples assume Python 3.12.
Why You Need to Create Arrays in Python in the First Place
Almost every program deals with collections of data. A single variable holds one employee’s name, but a real app needs all 10 names at once, plus their leave dates and status flags.
An array (in the general sense) is an ordered collection of values kept under one variable name. Python has no single built-in “array type” like C or Java, but offers several tools for the same purpose, each with different tradeoffs. Here is a simple structure before we touch any storage:
employee_names = ["Emily Carter", "Marcus Reed", "Olivia Bennett", "Noah Ramirez", "Ava Thompson"]
print(employee_names)
Output:
['Emily Carter', 'Marcus Reed', 'Olivia Bennett', 'Noah Ramirez', 'Ava Thompson']
That single line replaces five separate variables. As the app grows, you will store leave days, cities, and approval flags the same way.
Method 1: Create Arrays in Python Using a Built-in List
The list is the most common way to create arrays in Python. It is flexible, easy to read, and works well for small apps like this CLI tool.
Creating a Basic List
leave_requests = ["Emily Carter", "Marcus Reed", "Olivia Bennett"]
print(leave_requests)
Output:
['Emily Carter', 'Marcus Reed', 'Olivia Bennett']
You can see the output in the screenshot below.

A list is a built-in Python data structure that stores multiple items in one variable, keeps insertion order, and can change after creation.
Mixed vs Homogeneous Types
Lists can hold different types in one collection, called a mixed type list. This is convenient but can complicate later processing.
mixed_record = ["Emily Carter", 3, "Dallas", True]
print(mixed_record)
Output:
['Emily Carter', 3, 'Dallas', True]
That record mixes a name, a leave day count, a city, and a flag. A homogeneous list, where every item shares one type, is safer for calculations. Keep numbers in their own list, and an empty list (empty_queue = []) works as a starting placeholder.
Repeated and Default Values Without Aliasing
Fill a list with a default value using the multiplication operator. This works fine for simple, immutable values like booleans.
status_flags = [False] * 10
print(status_flags)
Output:
[False, False, False, False, False, False, False, False, False, False]
Be careful when the repeated item is mutable, like another list. Multiplying a list of lists creates references to the same inner list, a problem known as aliasing.
bad_grid = [[0] * 3] * 3
bad_grid[0][0] = 1
print(bad_grid)
Output:
[[1, 0, 0], [1, 0, 0], [1, 0, 0]]
Notice how changing one row changed all three, since every row points to the same inner list in memory. The fix is to build each row separately with a comprehension, covered next.
Using Ranges to Build a List
The built-in range() function generates number sequences, useful for day counters or request IDs.
day_range = list(range(1, 11))
print(day_range)
Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Parsing User Input Into a List
Our CLI app often turns raw text into a usable list, like when a manager types names separated by commas.
raw_input_str = "Emily Carter, Marcus Reed, Olivia Bennett"
parsed = [name.strip() for name in raw_input_str.split(",")]
print(parsed)
Output:
['Emily Carter', 'Marcus Reed', 'Olivia Bennett']
You can see the output in the screenshot below.

The split() method breaks the string into pieces, and strip() removes extra spaces. For more patterns, see this guide on converting a string to an array in Python and this one on converting a string to a list.
Method 2: Create Arrays in Python With List Comprehensions
A list comprehension is a compact way to build a list in one line, often replacing a longer loop.
squared_days = [day ** 2 for day in range(1, 6)]
print(squared_days)
Output:
[1, 4, 9, 16, 25]
Building a 2D Array Safely
A list comprehension fixes the aliasing problem from earlier by creating a fresh row each time.
grid = [[0] * 3 for _ in range(3)]
grid[0][0] = 1
print(grid)
Output:
[[1, 0, 0], [0, 0, 0], [0, 0, 0]]
You can see the output in the screenshot below.

This time only the first row changed, since each row is its own independent list. A 2D array like this fits well for tracking leave days across cities and weeks. For more patterns on building an empty grid first, see this guide on creating an empty matrix in Python.
Pro Tip: I always test small 2D structures with a quick print statement before wiring them into a real app. It takes ten seconds and saves an hour of chasing an aliasing bug.
Method 3: Create Arrays in Python With the array Module
Python’s built-in array module gives a more memory-efficient structure than a list, but only for one fixed type like integers or floats. A module is a file of reusable Python code you import with the import keyword.
import array
city_codes = array.array('i', [1, 2, 3, 1, 2, 3, 1, 2, 3, 1])
print(city_codes)
print(city_codes[0])
Output:
array('i', [1, 2, 3, 1, 2, 3, 1, 2, 3, 1])
1
Here 'i' tells Python to store signed integers, one code per city. The array module is a solid middle ground for compact numeric data without the weight of NumPy.
Method 4: Create Arrays in Python With NumPy
NumPy is a third-party library built for fast, numeric computing. It becomes the standard choice once your leave-tracking logic grows beyond small lists, especially for totals across many employees, as covered in this guide on Python NumPy arrays. Install it first with pip install numpy in your terminal, then import it as shown below.
Creating Arrays With zeros, arange, linspace, and full
import numpy as np
leave_days_used = np.zeros(10, dtype=int)
print(leave_days_used)
Output:
[0 0 0 0 0 0 0 0 0 0]
You can see the output in the screenshot below.

np.zeros() creates an array filled with zeros, ideal for a starting count of leave days for each of the 10 employees. See the guide on NumPy zeros for more.
day_counter = np.arange(1, 11)
print(day_counter)
Output:
[ 1 2 3 4 5 6 7 8 9 10]
np.arange() behaves like range() but returns a NumPy array directly. Two more generators round this out: np.linspace(0, 100, 5) creates evenly spaced values (handy for PTO percentage tiers), and np.full((3, 3), True) fills a given shape with one repeated value, like a 3×3 grid of approval flags.
Understanding dtype, shape, and Indexing
Every NumPy array has a dtype (the data type of its elements) and a shape (its dimensions). These matter because NumPy arrays must be homogeneous, unlike a Python list.
leave_days = np.array([5, 12, 8, 20, 3, 15, 9, 1, 30, 7])
print(leave_days.dtype)
print(leave_days.shape)
print(leave_days[3])
Output:
int64
(10,)
20
That last line uses indexing to grab the fourth employee’s leave days, 20, since indexing starts at 0. For more, see the guides on NumPy data types and NumPy indexing.
Working With 2D NumPy Arrays
A 2D NumPy array suits a table of leave days per employee per month, as covered in the guide on NumPy 2D arrays.
monthly_leave = np.array([
[3, 0, 2],
[1, 4, 0],
[0, 2, 5]
])
print(monthly_leave.shape)
print(monthly_leave[1, 2])
Output:
(3, 3)
0
Row 1, column 2 shows Marcus Reed took 0 leave days in the third month tracked.
Appending, Extending, and Concatenating Arrays
Lists and NumPy arrays handle growth differently as new leave requests come in.
Growing a List
pending_requests = ["Emily Carter"]
pending_requests.append("Marcus Reed")
pending_requests.extend(["Olivia Bennett", "Noah Ramirez"])
print(pending_requests)
Output:
['Emily Carter', 'Marcus Reed', 'Olivia Bennett', 'Noah Ramirez']
append() adds one item at the end. extend() adds every item from another list in one call. You can also combine two lists with batch_one + batch_two, which produces the same kind of merged list.
Concatenating NumPy Arrays
NumPy arrays do not support append() the same efficient way lists do, since resizing means creating a new array. Use np.concatenate() instead, covered in this guide on NumPy concatenate.
arr_a = np.array([1, 2, 3])
arr_b = np.array([4, 5, 6])
merged = np.concatenate((arr_a, arr_b))
print(merged)
Output:
[1 2 3 4 5 6]
Check dimensions before merging with the guide on NumPy shape, or start from scratch with NumPy empty arrays.
Converting Between Lists, Strings, and Arrays
Real apps convert data between formats constantly. Input arrives as a string, becomes a list, sometimes a NumPy array, then converts back for storage.
name_str = "Emily,Marcus,Olivia"
name_list = name_str.split(",")
back_to_array = np.array(name_list)
list_from_array = leave_days.tolist()
print(back_to_array)
print(list_from_array)
Output: