wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Creating lists in Python

Total questions: 41

Worksheet time: 21mins

Name
Class
Date
1.

What is the purpose of an elif statement in Python? (Tick 1 correct answer)

a)

to create a loop

b)

to define a function

c)

to handle multiple conditions in a selection statement

2.

What is the correct syntax for creating a list in Python? (Tick 1 correct answer)

a)

{"Monday", "Tuesday", "Wednesday"}

b)

["Monday", "Tuesday", "Wednesday"]

c)

(Monday, Tuesday, Wednesday)

3.

What type of data structure is a list in Python? (Tick 1 correct answer)

a)

static

b)

dynamic

4.

Each item within the list is referred to by an (a)   , which is its position in the list. (Fill in the blank)

5.

What will the following code print? days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] print(days[3]) (Tick 1 correct answer)

a)

Wednesday

b)

Thursday

c)

IndexError

d)

Tuesday

6.

What will the following code print? days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] print(days[7]) (Tick 1 correct answer)

a)

Saturday

b)

Sunday

c)

IndexError

7.

In Python, which keyword allows you to create a block of code that only executes when a certain condition is true?

(a)  

8.

Which if statement would correctly check if the variable score is greater than or equal to 80? (Tick 1 correct answer)

a)

if score >= 80:

b)

if score > 80:

c)

if score = 80:

d)

if score <= 80:

9.

Which of the following is correct when describing nested if statements? (Tick 1 correct answer)

a)

The first condition needs to be False before the next condition can be run.

b)

The first condition needs to be True before the next condition can be run.

10.

The = symbol in Python is used for ... (Tick 1 correct answer)

a)

equations.

b)

assignment.

c)

comparison.

11.

What keyword is used in Python to output text to the user?

(a)  

12.

S (a)   is used when there is more than one possible path for a program to follow. (Fill in the blank)

13.

Which list method can be used to add an item to the end of a list? (Tick 1 correct answer)

a)

list.insert()

b)

list.add()

c)

list.append()

d)

list.remove()

14.

Which list method can be used to remove the last item from a list if you do not know the index of the last item? (Tick 1 correct answer)

a)

list.pop()

b)

list.remove()

c)

list.delete()

d)

list.append()

15.

The operation list.sort(reverse=True) sorts a list in (a)   order (Fill in the blank)

16.

What list method is used to find the index of a specific item? (Tick 1 correct answer)

a)

list.find(item)

b)

list.search(item)

c)

list.index(item)

d)

index.find(item)

17.

is used when there is more than one possible path for a program to follow. (Fill in the blank)

(a)  

18.

Match the keyword to the definition. Select the correct keyword for: a collection of data in a particular sequence.

a)

selection

b)

list

c)

data structure

d)

index

19.

Match the keyword to the definition. Select the correct keyword for: the location of an item or element in a list or string.

a)

selection

b)

list

c)

data structure

d)

index

20.

Match the keyword to the definition. Select the correct keyword for: used when there is more than one possible path for a program to follow.

a)

selection

b)

list

c)

data structure

d)

index

21.

Match the keyword to the definition. Select the correct keyword for: an organised way to store data for easy use.

a)

selection

b)

list

c)

data structure

d)

index

22.

What is the correct way to access the first item in a list called names? (Tick 1 correct answer)

a)

names[0]

b)

names[1]

c)

names{0}

d)

names(0)

e)

names(1)

23.

What letter can you type in to join text and the values held by a variable in a print statement? (Tick 1 correct answer)

a)

j

b)

c

c)

f

d)

p

24.

What is an IndexError? (Tick 1 correct answer)

a)

when you have too many items in a list

b)

when you refer to an index that does not exist in a list

c)

when you have too few items in a list

d)

when you have two of the same index values in a list

25.

A list is a d (a)   data structure that can grow or shrink as you add or remove items. (Fill in the blank)

26.

A (a)   is a data type that is a collection of characters. (Fill in the blank)

27.

Lists are (a)   , which means that their contents can be modified without having to create a new list. (Fill in the blank)

28.

Which code would check the first character of name1 does not appear anywhere in name2? (Tick 1 correct answer)

a)

name1[0] == name2[0]

b)

len(name1) != len(name2)

c)

name1[0] not in name2

29.

Which of the following statements about strings is true? (Tick 1 correct answer)

a)

Strings are mutable.

b)

Strings are immutable.

c)

Strings can only hold letters.

30.

What code would you use if you wanted to check the value of the first letter held in the string message = "Hello"? (Tick 1 correct answer)

a)

message[0]

b)

message[1]

c)

message["H"]

d)

message[first]

31.

If you update the value held by a string, the previous value is (a)   . (Fill in the blank)

32.

Match the terms with their definitions: Choose the term that matches this definition — a collection of characters.

a)

operator

b)

list

c)

shuffle

d)

string

e)

immutable

33.

Match the terms with their definitions: Choose the term that matches this definition — a symbol or word that instructs the computer to perform a calculation.

a)

operator

b)

list

c)

shuffle

d)

string

e)

immutable

34.

Match the terms with their definitions: Choose the term that matches this definition — not able to be changed.

a)

operator

b)

list

c)

shuffle

d)

string

e)

immutable

35.

Match the terms with their definitions: Choose the term that matches this definition — a collection of data in a sequence.

a)

operator

b)

list

c)

shuffle

d)

string

e)

immutable

36.

Match the terms with their definitions: Choose the term that matches this definition — randomly reorder the contents of a list.

a)

operator

b)

list

c)

shuffle

d)

string

e)

immutable

37.

What is the primary purpose of a for loop in Python? (Tick 1 correct answer)

a)

to execute code indefinitely

b)

to repeat a block of code a specific number of times

c)

to handle errors in code

d)

to define variables

38.

What is the index of the second item in a list?

(a)  

39.

What can be used to perform calculations in Python? (Tick 1 correct answer)

a)

variables

b)

operators

c)

loops

d)

strings

40.

Which statement about performing mathematical operations on list items in Python is true? (Tick 1 correct answer)

a)

Items must be copied to a new variable first.

b)

Operations are only for lists with numbers.

c)

Operations can be performed directly on list items.

d)

Items need to be converted to strings for operations.

41.

What does the shuffle() function do to a list in Python? (Tick 1 correct answer)

a)

sorts the list in ascending order

b)

reverses the order of the list

c)

randomly reorders the list items

d)

removes duplicates from the list