Lists and Arrays of Data
A list (or array) is a way to store many pieces of related information together under one name, in order.
Reading is good — doing is better. Practice Lists and Arrays of Data as an interactive lesson.
Try the lessonDefinition
A list, also called an array in many programming languages, is a collection of items stored in a set order. Instead of making a separate variable for every piece of data, you put all the related data into one list. Each item sits in a numbered slot called an index, and you can look up, change, or use any item by referring to its index number.
Remember the rule
First item = index 0, last item = index (length - 1). When in doubt, start counting from zero!
Key words
- Array
- Another word for a list used in coding — a group of items stored in order under one name.
- Index
- The number that tells you where an item lives in the list. Most coding languages start counting at 0, not 1.
- Element
- One single item inside a list or array.
- Length
- How many items are in the list in total.
- Zero-based indexing
- A rule in most programming languages where the first item is at position 0, the second at position 1, and so on.
- Variable
- A named container that holds a value — a list is a special variable that holds many values at once.
- Append
- Adding a new item to the end of a list.
- Access
- Looking up or using a specific item in a list by its index number.
Worked examples
You have a list of three favorite colors: colors = ['red', 'blue', 'green']. What is colors[0]?
→ 'red' — because index 0 is always the first item in the list. · Remember, we start counting at 0, not 1, so the first slot is index 0.
Using the same list colors = ['red', 'blue', 'green'], what is colors[2]?
→ 'green' — index 2 is the third item because we started counting at 0. · This trips up many beginners who expect index 2 to be the second item.
You have scores = [95, 88, 72, 100]. How many elements are in the list, and what is the last index number?
→ There are 4 elements. The last index is 3 (which is 4 - 1 = 3), holding the value 100. · The last index is always one less than the total length of the list.
You start with pets = ['dog', 'cat']. You append 'fish'. What does the list look like now?
→ pets = ['dog', 'cat', 'fish']. The new item is added to the end at index 2.
A student writes: names = ['Alice', 'Bob', 'Carlos']. They want Bob's name. They write names[2]. Is that right?
→ No. Bob is at index 1, not 2. names[1] gives 'Bob'. names[2] gives 'Carlos'. · Always count starting from 0: Alice=0, Bob=1, Carlos=2.
You need to store the daily high temperatures for a week: [88, 91, 79, 85, 90, 77, 82]. How would you find Thursday's temperature if Monday is index 0?
→ Thursday is the 4th day, so its index is 3. temps[3] = 85. · Map real-world order to index by subtracting 1 — then remember we start at 0.
Common mistakes
- Using index 1 to get the first item instead of index 0 — the off-by-one error is the most common list mistake.
- Trying to access an index that does not exist, like asking for item at index 5 in a list that only has 5 items (valid indexes are 0–4).
- Confusing the length of the list with the last valid index — a list of 6 items has a last index of 5, not 6.
- Forgetting that all items in a list should be related — storing random, unrelated data in one list makes code confusing.
- Accidentally overwriting the whole list with one value instead of changing just one element (e.g., writing colors = 'red' instead of colors[0] = 'red').
FAQs
Why do lists start at index 0 instead of 1?
It comes from how computers store data in memory — the index tells the computer how many steps to jump from the start of the list, and zero steps means you are already at the first item. Most programming languages follow this rule.
What is the difference between a list and an array?
They are very similar ideas. 'Array' is the word used in languages like JavaScript, Java, and C. 'List' is often used in Python and in everyday conversation. For 6th grade purposes, treat them as the same thing — an ordered collection of items.
Can a list hold different types of data, like numbers and words together?
In some languages like Python, yes. In others like Java, a basic array must hold all the same type. For beginners, it is best practice to keep one type of data per list to avoid confusion.
How do I find the last item in a list without counting every element?
Use the length of the list minus 1. If a list has 10 items, the last index is 9. Many languages also let you use a shortcut like list[-1] in Python to grab the last item directly.
Why would I use a list instead of just making separate variables?
Imagine storing 30 student names — you would need 30 different variables! A list keeps them all together under one name, lets you loop through them easily, and makes your code much shorter and cleaner.
Can I change an item in a list after I create it?
Yes! You just use the index to point to the item you want to change. For example, colors[0] = 'purple' replaces whatever was at index 0 with 'purple'.
Want the whole picture for your child?
Every K–6 subject, an AI tutor that teaches step by step, unlimited practice, and a reward world.
Start a 3-day free trial