thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

01.02 · Create and access lists / Watch · 12 min

Keep related values together in a list

A list holds an ordered sequence. Its length counts the items, not the letters in their names.

Activity 2 of 5 in Create and access lists

All courses

Python 3: Lists / 01.02

Create Python lists

Not started

Create ordered collections, combine them and count their items.

More options

Your lesson progress

Walkthrough: not startedPractice: not started

Empty: not started. Yellow: in progress. Green: complete. Marking the whole activity complete does not replace your test results. These circles save in this browser for this pilot.

Rob groups an apple, banana and cherry into a list and counts three items.
Rob’s comic strip · Create and access lists

ORIGINAL WALKTHROUGH · 6:57

Watch with Rob.

Pause whenever you want to try a change. You can return to the lesson at any time.

LEARN WITH THE CODE ZONE

Unlock this video walkthrough

Written lessons and coding practice are free. Video walkthroughs are included with a paid Code Zone membership or an active free trial.

Have a Code Zone website account? Use your learning account’s email to get a six-digit sign-in code, or use your existing website password.

Need a website account? Paid Skool members and active trial members can use the email from their membership questions to request a sign-in code. No invite link or Skool password needed.

Close this window to keep practicing. After signing in, you’ll return to this lesson.

Video walkthroughs are included with an active Code Zone membership. The written lesson and practice are free.

Open video & code editor (opens in a new tab)

Starter source code for VS Code

Copy the source below or download the file to follow along in VS Code.

The download includes a lesson link in each file and a README so you can find your way back.

main.py
main.pypython · example
# Code along with Rob: Create Python lists
# Create string, numeric and mixed lists.
# Combine two lists into a new list and compare the originals.
# Use len to count items; try an empty list.
# Predict each result, then press play.

Square brackets create a list

Put comma-separated values inside square brackets. Strings still need quotes; numbers and Boolean values keep their normal Python spelling. Empty brackets create an empty list.

A list preserves item order and allows duplicate values. It can hold mixed types, although keeping related values together often makes later code simpler.

Square brackets create a list
lists.pypython · example
fruits = ["apple", "banana", "cherry"]
numbers = [1, 2, 3]
mixed = ["Ada", 42, True]
print(fruits)
print(len(mixed))  # 3
print([])
Open workspace to paste this example (opens in a new tab)

Combine lists without changing the originals

The + operator produces a new list with the left list’s items followed by the right list’s items. It does not add the numbers inside those lists.

The original lists remain unchanged. This distinction matters when you want a combined roster and still need each team.

Combine lists without changing the originals
lists.pypython · example
first_team = ["Ada", "Rob"]
second_team = ["Grace"]
roster = first_team + second_team
print(roster)
print(first_team)
print(len(roster))  # 3
Open workspace to paste this example (opens in a new tab)

Count items, not characters

len(fruits) returns the number of items. A long fruit name still occupies one list position. An empty list has length zero.

The next practice adapts the source’s create/combine/count exercises to fixed inputs so the checks can give predictable feedback. After passing, try your own animals, foods or numbers.

Build it one step at a time

Prefer learning by typing? Work through short instructions, run the Python code and check each change before continuing. Your guided project saves separately from the challenge below.

The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.

Start mini-lesson(opens in a new tab)

4 steps · Saved work · Instant feedback

YOUR TURN

Combine fruit lists

Create all_fruits from the two source lists and fruit_count from its length. Print the combined list, then its count. Preserve both source lists.

Expected output
['apple', 'banana', 'cherry']
3

Keep the starting inputs. Print these lines in this order, without extra output.

  • Store a three-item count
  • Preserve the first list
  • Preserve the second list
  • Store all fruits in order

Edit Python, then run it. Check challenge checks your output and the listed Python requirements. Your code saves on this browser after a short pause. Sign in and choose Save account draft to keep it across devices. Word wrap is enabled.

Ready to checkRun the checks to see your results here.

Need a nudge?

Make a new list

Use the two existing list names on either side of +. Store that expression in all_fruits.

Count the combined items

Call len with all_fruits, rather than writing the count by hand.

Replace your editor code?

Your current work will be replaced. Choose Cancel to keep it.

Ready to try it?

Practice in your browser and see your results.

Progress details

Have a question?

Ask the Code Zone community.

Ask a question in The Code Zone (opens in a new tab)

Continue learning

ONE STEP FORWARD

A list groups values in order. Combine lists with + and count their items with len.