wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Chapter 9 - Chapter 10 Revision Question Python

Total questions: 45

Worksheet time: 1hrs 20mins

Name
Class
Date
1.

Which of the following is the correct way to define a list in Python?

a)

list = (1, 2, 3)

b)

list = {1, 2, 3}

c)

list = [1, 2, 3]

d)

list = <1, 2, 3>

2.

What is the index of the first element in a list?

(a)  

3.

What does len([1, 2, 3, 4]) return?

(a)  

4.

Which method is used to add an item at the end of a list?

a)

add()

b)

insert()

c)

append()

d)

extend()

5.

What will be the output of this code?

(a)  

6.

What is the output of list(range(1, 5))?

(a)  

7.

What does my_list[-1] return?

a)

First item

b)

Last item

c)

Middle item

d)

Error

8.

What will the following code output?

(a)  

9.

What is the output of this code?

(a)  

10.

What will list1 = [1, 2] + [3, 4] result in?

(a)  

11.

What is a list in Python?

4 lines
12.

How does the append() method differ from insert()?

4 lines
13.

What is the difference between list1 = [1, 2, 3] and list2 = list1.copy()?

4 lines
14.

Write Python code to remove the value 5 from the list [2, 5, 7, 5].

4 lines
15.

Write a Python statement to create a list of squares from 1 to 5 using list comprehension.

4 lines
16.

The following code is intended to replace all even numbers in the list with 0, but it doesn't work as expected. Analyze the mistake and correct it.

4 lines
17.

Analyze the following code. Why does it print three copies of the same list?

4 lines
18.

This program aims to insert 100 between 2 and 3. Why doesn't it work?

4 lines
19.

The following code is meant to remove all occurrences of 5. But it raises an error. Why, and how can it be fixed?

4 lines
20.

The following code is intended to create a new list that contains only the odd numbers from the original list. However, the output is incorrect. Analyze and correct the mistake.

4 lines
21.

Which of the following is a correct way to create a set in Python?

a)

set = {}

b)

set1 = set([1, 2, 3])

c)

set1 = (1, 2, 3)

d)

set1 = [1, 2, 3]

22.

What is the characteristic of a Python set?

a)

Ordered and mutable

b)

Unordered and mutable

c)

Ordered and immutable

d)

Unordered and immutable

23.

What will be the output of the following code?

(a)  

24.

What will the output be?

(a)  

25.

Which method is used to add an element to a set?

a)

add()

b)

append()

c)

insert()

d)

extend()

26.

Which of the following defines an empty tuple?

a)

()

b)

{}

c)

[]

d)

||

27.

Which of the following is immutable in Python?

a)

List

b)

Set

c)

Dictionary

d)

Tuple

28.

What is the output of this code?

(a)  

29.

What will be the output of this code?

(a)  

30.

Which of these operations is not allowed on a tuple?

a)

Indexing

b)

Iteration

c)

Slicing

d)

Assignment to an element

31.

How do you create an empty dictionary named dict?

(a)  

32.

What does this code print?

(a)  

33.

Which method returns all the keys from a dictionary?

a)

d.values()

b)

d.items()

c)

d.keys()

d)

d.get()

34.

What is the output?

(a)  

35.

How to correctly check if a key exists in a dictionary named dict?

(a)  

36.

The following code aims to update a set with new elements. It doesn’t work as expected. Identify and correct the issue.

4 lines
37.

You are checking for membership in a large dataset. Which data type is more efficient and why?

4 lines
38.

Analyze the error in the following code:

x, y = (1, 2, 3)

4 lines
39.

Why does the following code raise an error?
t = (1, 2, 3)

t[1] = 10

4 lines
40.

What will be the output of this code and why?
d = {'a': 1, 'a': 2}

print(d)

4 lines
41.

Write a program to create a tuple with 5 elements and print each element using a loop.

4 lines
42.

Write a program to count the frequency of each character in a string using a dictionary.

4 lines
43.

Write a program to find the common elements between two sets.

4 lines
44.

Write a program to merge two dictionaries into one.

4 lines
45.

Write a program to find the maximum and minimum values in a tuple.

4 lines