📋 1D Arrays (Lists)

Learn how to store multiple values in a single variable using arrays (called lists in Python).

What you'll learn:

  • What arrays are and why we use them
  • Creating and accessing array elements by index
  • Modifying array elements
  • Using loops to iterate through arrays
  • Common array operations: length, append, remove

Learning Path

Follow these activities in order.

Key Vocabulary

array / list

A data structure that stores multiple values in a single variable. In Python, we use lists.

element

A single item stored in an array. ["a", "b", "c"] has 3 elements.

index

The position of an element. Starts at 0! First element is at index 0.

length

The number of elements in an array. Use len(array) to find it.

append

Add an element to the end of an array. array.append(value)

iteration

Going through each element of an array one by one, usually with a loop.

Quick Reference

arrays_1d_examples.py
# Creating an array (list)
scores = [85, 92, 78, 90, 88]
names = ["Alice", "Bob", "Charlie"]
empty = []

# Accessing elements by index (starts at 0!)
print(scores[0])    # First element: 85
print(scores[2])    # Third element: 78
print(scores[-1])   # Last element: 88

# Modifying elements
scores[0] = 95      # Change first element to 95

# Array length
print(len(scores))  # 5

# Adding and removing elements
scores.append(100)  # Add 100 to the end
scores.remove(78)   # Remove first occurrence of 78

# Looping through an array - by element
for score in scores:
    print(score)

# Looping through an array - by index
for i in range(len(scores)):
    print("Index", i, "=", scores[i])