Lists – Creation

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Lists – Creation

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. How do you create a list?
A Square brackets []
B Parentheses ()
2. What does [] create?
A An empty string
B An empty list
3. Can a list hold different types?
A Yes strings, numbers, booleans, etc.
B No only one type
4. What does len([1, 2, 3]) return?
A 2
B 3
5. Are list items ordered?
A Yes they keep their order
B No random order

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1nums = (1, 2, 3) nums.append(4) AError: Missing closing bracket ]
2items = [1, 2, 3 print(items) BOutput: 3
3colors = ['red', 'blue', 'green'] CError: Tuples have no append()
4mixed = [1, 'hi', True, 3.5] DValid: List of strings
5nums = [1, 2, 3] print(len(nums)) EOutput: []
6items = [] print(items) FOk: Mixed types in a list

Definitions

List

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
colors = _'red', 'blue', 'green'_
2.
numbers = [10, 20, 30] print(___(numbers))
3.
empty = __
4.
pets = ['cat'_ 'dog'_ 'fish']
5.
names = ['Alice', 'Bob'] _____(names)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A # Create a list of colors
B colors = ('red', 'blue', 'green')
C print('First:', colors[0])
D print('Count:', len(colors))
Question 2
A # Create a list of colors
B colors = {'red', 'blue', 'green'}
C print('First:', colors[0])
D print('Count:', len(colors))
Question 3
A # Create a list of colors
B colors = ['red' 'blue' 'green']
C print('First:', colors[0])
D print('Count:', len(colors))
Question 4
A # Create a list of numbers
B numbers = [1, 2, 3,]
C print('First:', numbers[0])
D print('Count:', len(numbers))
Question 5
A colors = [red, blue, green]
B print('First:', colors[0])
C print('Count:', len(colors))
D print('Done')

Answer Key

Lists – Creation
Section A: Quick Questions
Q1
A — Square brackets []
Q2
B — An empty list
Q3
A — Yes strings, numbers, booleans, etc.
Q4
B — 3
Q5
A — Yes they keep their order
Section B: Match the Pairs
Q1
nums = (1, 2, 3) nums.append(4) → Error: Tuples have no append()
Q2
items = [1, 2, 3 print(items) → Error: Missing closing bracket ]
Q3
colors = ['red', 'blue', 'green'] → Valid: List of strings
Q4
mixed = [1, 'hi', True, 3.5] → Ok: Mixed types in a list
Q5
nums = [1, 2, 3] print(len(nums)) → Output: 3
Q6
items = [] print(items) → Output: []
Section C: Definitions
Q1
List — An ordered collection of items in square brackets.~~[]
Section D: Fill in the Blanks
Q1
colors = ['red', 'blue', 'green']
Q2
numbers = [10, 20, 30] print(len(numbers))
Q3
empty = []
Q4
pets = ['cat', 'dog', 'fish']
Q5
names = ['Alice', 'Bob'] print(names)
Section E: Spot the Error
Q1
B — Use square brackets [] for lists, not parentheses (tuples)
Q2
B — Use square brackets [] for lists, not curly braces (sets)
Q3
B — Items must be separated by commas
Q4
B — Trailing comma is valid Python but unnecessary and sloppy
Q5
A — String items need quotes: without quotes Python looks for variables