wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

List,Tuples,Dictionary

Total questions: 19

Worksheet time: 12mins

Name
Class
Date
1.

Elements of a tuple can be accessed in the same way as list or string using

a)

Indexing

b)

Slicing

c)

Both indexing and slicing

d)

None of the above

2.

init_tuple = ('Python') * 3

print(type(init_tuple))

a)

A. <class ‘tuple’>

b)

B. <class ‘str’>

c)

C. <class ‘list’>

d)

D. <class ‘function’>

3.

What is the output of the below Python code?

a = {(1,2):1,(2,3):2}

print(a[1,2])

a)

A. Key Error

b)

B. {(2,3):2}

c)

C.  1

d)

D. {(1,2):1}

4.

The code below has a Python function writing to a dictionary. What will it print in the end?

a)

A. 1

b)

B. 2

c)

C. 3

d)

D. 4

5.

What will be the output of the Python code given below?

dict = {'c': 97, 'a': 96, 'b': 98}

for _ in sorted(dict):

print (dict[_])

a)

A. 96 98 97

b)

B. 96 97 98

c)

C. 98 97 96

d)

D. NameError

6.

>>colors = ["red", "green", "burnt sienna", "blue"]

>> "yellow" in colors

What is the result of the yellow in colors expression?


a)

ValueError: 'yellow' is not in list

b)

4

c)

3

d)

False

7.

What’s the main difference between Python lists and tuples?

a)

Lists can hold any data type and tuples can only contain int and str objects.

b)

Lists are immutable and tuples are mutable.

c)

Lists are faster and tuples are slower.

d)

Lists are mutable and tuples are immutable.

8.

Write the Python code that prints out Captain Kirk’s email address from the employee dictionary below:

employee = { "id": 1701, "name": "James T Kirk", "email": "jtkirk@starfleet.com", "position": "captain", }

# Add your code below:

(a)  

9.
  • What will be the output of the following Python code? >>>t = (1, 2) >>>2 * t

a)
  • A.

    (1, 2, 1, 2)

b)
  • B.

    [1, 2, 1, 2]

c)
  • C.

    (1, 1, 2, 2)

d)
  • D.

    [1, 1, 2, 2]

10.

Suppose t = (1, 2, 4, 3), which of the following is incorrect?

a)

a) print(t[3])

b)

b) t[3] = 45

c)

c) print(max(t))

d)

d) print(len(t)

11.

What will be the output of the following Python code?

a)

a) [2, 3, 9]

b)

b) [1, 2, 4, 3, 8, 9]

c)

c) [1, 4, 8]

d)

d) (1, 4, 8)

12.

What will be the output of the following Python code?

a)

a) 1

b)

b) 2

c)

c) 5

d)

d) Error

13.

What will be the output of the following Python code?

a)

a) 30

b)

b) 24

c)

c) 33

d)

d) 12

14.

What is the output of the following code

 

a)

True

b)

 False

15.

What will be the output of the following Python code?

a)

A. [1,2]

b)

B. [8,9]

c)

C. [1,3,5,7,9]

d)

D. [1,2,3]

16.

What is the correct command to shuffle the given Python list?

fruit=['apple', 'banana', 'papaya', 'cherry']

a)

A. fruit.shuffle()

b)

B. shuffle(fruit)

c)

C. random.shuffle(fruit)

d)

D. random.shuffleList(fruit)

17.

What will be the output of the following Python code?

a)

A. Exception

b)

B. 5

c)

C. 4

d)

D. None

18.

What will be the output of the following Python code?

print([x**2 for x in range(5)])

a)

[1, 4, 9, 16, 25]

b)

[0, 1, 4, 9, 16]

c)

[0, 1, 2, 3, 4]

d)

[0, 1, 2, 3, 4, 5]

19.

What will be the output of the following Python code?

print({x: x**2 for x in range(3)})

a)

A. {0: 0, 1: 1, 2: 4}

b)

B. {0: 0, 1: 1, 2: 2}

c)

C. {0: 0, 1: 1, 2: 3}

d)

D. Error