wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Lists

Total questions: 27

Worksheet time: 14mins

Name
Class
Date
1.

Which of these is the correct code for creating a list of names?

a)

nameList = John, Harry, Jesse, John, Harry, Harry

b)

nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")

c)

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

d)

nameList = [John, Harry, Jesse, John, Harry, Harry]

2.

List items have an index number. In the following list, which item has the index number of 3?

["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

"John"

b)

"Harry"

c)

"Jesse"

3.

The list needs one more name added to the end - "Felipe". Which piece of code below would do this?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList.append(Felipe)

b)

append(nameList,"Felipe")

c)

nameList.append["Felipe",7]

d)

nameList.append("Felipe")

4.
What output will this code produce?
a)
blue
b)
green
c)
red
d)
error
5.

Consider this list, what will be the highest index the list can have:

li=[1,2,3,4,5]

a)

2

b)

3

c)

4

d)

5

6.

The count() method returns the number of times the specified element appears in the list.

What is the output of this code?

a)

3

b)

2

c)

1

d)

0

7.

What is the output of this code?

a)

X

b)

Y

c)

Error

8.

Which of the following function is used to count the number of elements in a list ?

a)

count( )

b)

find( )

c)

len( )

d)

index( )

9.

mylist = ["a","b"]

mylist[1] = "c"'

print(mylist)

a)

["a","c"]

b)

["a","b"]

c)

["a","b","c"]

d)

mylist

10.

What is the output of program below?


bicycles = ['trek', 'cannondale', 'redline', 'specialized']

print(bicycles[-1])

a)

trek

b)

cannondale

c)

redline

d)

specialized

11.

a = [2, 5, 8, 1]

print("a[2]")

What is the output above?

a)

5

b)

8

c)

a[2]

d)

2

12.

filename="example.txt"

with open(filename, "w") as myfile:

myfile.write("Pershendetje")

What happens here?

a)

a file called 'example' is being read

b)

a file called 'example' is created and some text is saved in it.

c)

The text in the 'example' file is assigned to a variable

d)

a variable called filename is created and it's value is printed on a file

13.

What do you think is the difficulty level of Python?

a)

Very difficult

b)

A little difficult

c)

Average

d)

Not difficult

e)

Easy

14.

Select the one(s) which suits you.

a)

I can write codes in python

b)

I can create a list and let user add items to the list

c)

I can create a text file and print some text to it

d)

I can read some text from a file

15.

Which of these is the best description of a list in Python?

a)

A list is a collection of data that has an order and can be changed

b)

A list is a lot of variables

c)

A list is used for shopping

d)

A list is a collection of data that cannot hold duplicated data and cannot be changed

16.

What is the output of the program above ?

a)

b is bigger

b)

a is bigger

c)

Syntax error : tuples can't be compared

17.

sampleSet = {"Jodi", "Eric", "Garry"}

sampleSet.add(1, "Vicki")

print(sampleSet)

a)

{‘Vicki’, ‘Jodi’, ‘Garry’, ‘Eric’}

b)

{‘Jodi’, ‘Vicki’, ‘Garry’, ‘Eric’}

c)

The program executed with error

18.

var1 = 1

var2 = 2

var3 = "3"

print(var1 + var2 + var3)

a)

6

b)

33

c)

123

d)

Error. Mixing operators between numbers and strings are not supported.

19.

________________method removes all items from the particular dictionary.

a)

clear( )

b)

pop( )

c)

del ( )

20.
Which symbol surrounds a dictionary?
a)
{
b)
(
c)
[
d)
:
21.

A collection of objects which ordered, immutable, and allows duplicate values.

a)

Tuple

b)

Sets

c)

Module

d)

Dictionary

22.

A collection that is unordered, changeable, and does not allow duplicates.

a)

Tuple

b)

Sets

c)

Module

d)

Dictionary

23.

A collection which is unordered and unindexed.

a)

Tuple

b)

Sets

c)

Module

d)

Dictionary

24.

What will be the output?

var1=['sam', "Pam", 12,44]

var1[3]="Ram"

print(var1)

a)

['sam', 'Pam', 12, 44]

b)

['sam', 'Pam', 12, 'Ram']

c)

It will give an error

d)

['sam', 'Pam', 'Ram',44]

25.

Which of the statements are true for the code below:


list1=["Red","Green","Yellow","Orange","Black"]


if "Red" in list1 and "Green" in list1 and "Yellow" in list1:

print("We have all the colors of traffic lights")

a)

Print statement will be executed if the list has red/yellow/Blue

b)

Print statement will be executed if the list has all the three colors

c)

It will give syntax error

d)

None of these

26.

Which statement is correct?

a)

List is immutable && Tuple is mutable

b)

List is mutable && Tuple is immutable

c)

List & Tuple are mutable

d)

List & Tuple are immutable

27.

Which of these about a dictionary is false?

a)

The values of a dictionary can be accessed using keys

b)

The keys of a dictionary can be accessed using values

c)

Dictionaries aren't ordered

d)

Dictionaries are mutable