wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Dictionary,Tuple and set

Total questions: 35

Worksheet time: 18mins

Name
Class
Date
1.

The code snippet above outputs

a)

error

b)

None

c)

NaN

d)

-1

2.

What is the output of the code above

a)

None

b)

Syntax Error

c)

-1

d)

Code doesn't compile

3.

The output of the code above is

a)

Key Error

b)

4

c)

Math

4.

The code above prints

a)

Math

Physics

Chemistry

English

b)

4

3.8

3.6

3.7

c)

None

None

None

None

d)

NaN

NaN

NaN

NaN

5.

What is the output of the program above

a)

e

b)

y

c)

t

d)

g

6.

The output of the code above is

a)

[101, 102, 103, 104]

b)

[3.6, 3.7, 3.8, 4]

7.

What is the output of the code above

a)

[3.6, 3.7, 3.8, 4]

b)

[101, 102, 103, 104]

8.

Assume the key is the student's id and the value is the grade. Which of the following code will get the grade of student id 102.

a)

grades[102]

b)

grades.get(102)

c)

grades[2]

d)

grades[3]

e)

grades.key(102)

9.

Which of the following are valid ways to create a dictionary like this

a)
b)
c)
d)
e)
10.

Which of the following code deletes the key 103 and its value

a)

del grades[103]

b)

grades.pop(103)

c)

del grades["103"]

d)

grades.pop("103")

e)
11.

What is the output of the code above

a)

3.9

b)

4

c)

Syntax error

12.

What is the output of the program above

a)

7

b)

6

c)

5

d)

9

e)

4

13.

How to fix the syntax error above ?

a)

grades.pop("Science", None)

b)

grades.pop["Science","None"]

c)

del grades["Math"]

d)

del grades["Math", None]

14.

What is the problem with the code above ?

a)

Dictionary cannot be changed during an iteration

b)

This code will run fine (without syntax errors)

c)

After all the grades are popped, there are no elements remaining. The print statement will throw a syntax error.

15.

Tuples in Python are mutable

a)

False

b)

True

16.

How to create a single element tuple

a)

(1,)

b)

(1)

c)

{1}

d)

[1]

e)

tuple([1])

17.

Result of the program above is

a)

('1', '2', '3', '4', '5')

b)

(1, 2, 3, 4, 5)

c)

12345

d)

"12345"

18.

What is the output of the program above

a)

<class 'tuple'>

b)

<class 'None'>

c)

<class 'list'>

d)

<class 'int'>

19.

What is the output of the code above

a)

(1, '2', 3, 4, 5)

b)

syntax error

c)

(1, 2, 3, 4, 5)

d)

('1', '2', '3', '4', '5')

20.

Which of the following is true

a)

a is assigned a value of 1

b)

b is assigned a value of [2,3]

c)

b is assigned a value of (2,3)

d)

b is assigned a value of 2

21.

What is the output of the program above ?

a)

b is bigger

b)

a is bigger

c)

Syntax error : tuples can't be compared

22.

What is the output of the code above ?

a)

1 4

b)

1

c)

1 None

d)

1 [2,3,4]

e)

1 (2,3,4)

23.

What is the output of the program above ?

a)

True

b)

False

24.

Which of the following is used to define a block of code in Python language?

a)

Key

b)

Indentation

c)

Brackets

d)

All of the mentioned

25.

What will be the value of the following Python expression?4 + 3 % 5

a)

2

b)

7

c)

1

d)

4

26.

Is Python code compiled or interpreted?

a)

Python code is both compiled and interpreted

b)

Python code is neither compiled nor interpreted

c)

Python code is only interpreted

d)

Python code is only compiled

27.

Which keyword is used for function in Python language?

a)

Function

b)

Fun

c)

Define

d)

def

28.

Which of the following is the correct extension of the Python file?

a)

.pl

b)

.py

c)

.pl

d)

p

29.

What will be the type of the variable sorted_numbers in the below code snippet?

numbers = (4, 7, 19, 2, 89, 45, 72, 22)

sorted_numbers = sorted(numbers)

print(sorted_numbers)

a)

list

b)

tuple

c)

string

d)

int

30.

What is the output of the following code snippet ?

a)

2 2

b)

error

c)

2 3

d)

None of the above

31.

Which one of the following is the correct output of the following code snippet?

a)

[1] [2] [3]

b)

[1, 2, 3]

c)

[1] [1, 2] [1, 2, 3]

d)

None of the above

32.

What is the output of the following code snippet ?

a)

1

b)

2

c)

error

d)

None of the above

33.

Which of these is the definition for packages in Python

a)

A set of programs making use of Python modules

b)

A set of main modules

c)

A folder of python modules

d)

A set of programs making use of Python modules

34.

Which of the following functions is a built-in function in python?

a)

sqrt()

b)

factorial()

c)

print()

d)

seed()

35.

What does pip stand for python?

a)

Preferred Installer Program

b)

Pip Installs Python

c)

Pip Installs Packages

d)

All of the mentioned