wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

LECTURE 03 Quizs (20.11.2025)

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

Which method would you use to remove a specific item from a Python set if you are not sure the item exists?

a)

remove()

b)

discard()

c)

pop()

d)

delete()

2.

What will be printed by the following code? (Try it in a Python interpreter!) ```python data = [10, 20, 10, 30, 20] print(list(set(data))) ```

a)

[10, 20, 10, 30, 20]

b)

[10, 20, 30]

c)

[30, 10, 20] (order may vary)

d)

[20, 30, 10, 10, 20]

3.

You are designing a program that must store a collection of items where order does not matter and duplicates must be removed automatically. Which Python data type should you choose and why?

a)

List, because it is ordered and allows duplicates

b)

Tuple, because it is immutable

c)

Set, because it is unordered and stores only unique elements

d)

Dictionary, because it stores key-value pairs

4.

True or False: A Python list is an ordered collection of items that can be changed after creation.

a)

True

b)

False

5.

You need to measure the execution time of a function in Python as accurately as possible. Which approach should you use and why?

a)

Use time.time() because it is simple

b)

Use time.clock() because it is deprecated

c)

Use time.perf_counter() because it provides the highest available resolution timer

d)

Use datetime.now() because it returns the current date and time

6.

True or False: Tuples are generally preferred over lists when the data must remain unchanged.

a)

True

b)

False

7.

Which method removes all items from a Python set?

a)

clear()

b)

remove()

c)

discard()

d)

pop()

8.

True or False: Python sets automatically remove duplicate elements.

a)

True

b)

False

9.

Why are sets more efficient than lists for checking if an item exists?

a)

Sets are ordered

b)

Sets use hashing for fast lookups

c)

Sets store data in arrays

d)

Sets are immutable

10.

Which Python data type is best for removing duplicates from a sequence?

a)

List

b)

Dictionary

c)

Set

d)

Tuple

11.

Write a Python function that takes a list with duplicate values and returns a new list with only unique values. Which of the following implementations is correct? (Test it in a Python interpreter!)

a)

```python def unique(data): return list(set(data)) ```

b)

```python def unique(data): return data ```

c)

```python def unique(data): return set(list(data)) ```

d)

```python def unique(data): return data.sort() ```

12.

A Python module is:

a)

A folder containing multiple files

b)

A single Python file (.py)

c)

A built-in function

d)

A compiled program

13.

True or False: Sets in Python are ordered collections.

a)

True

b)

False

14.

Which method would you use to add an item to a Python list?

a)

add()

b)

append()

c)

insert()

d)

update()

15.

Which function is recommended for measuring the execution time of a Python process?

a)

time.time()

b)

time.clock()

c)

time.perf_counter()

d)

datetime.now()

16.

Given the function: ```python def get_unique_elements(data): unique_list = list(set(data)) print(unique_list) ``` What is the main advantage of using `set(data)` in this function?

a)

It sorts the data

b)

It removes duplicate elements efficiently

c)

It makes the list immutable

d)

It reverses the list

17.

What is the result of running the following code? ```python print(set([1, 2, 2, 3])) ```

a)

{1, 2, 2, 3}

b)

[1, 2, 3]

c)

{1, 2, 3}

d)

(1, 2, 3)

18.

If you want to ensure that a collection of items cannot be changed, which Python data type should you use?

a)

List

b)

Set

c)

Tuple

d)

Dictionary

19.

Which of the following best describes the difference between a Python module and a package?

a)

A module is a folder, a package is a file

b)

A module is a single file, a package is a folder containing modules

c)

Both are the same

d)

A package is a function, a module is a class

20.

True or False: Tuples in Python are mutable.

a)

True

b)

False