Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Variables, Data Types, Loops, Operators, Lists, Sets, Dictionary, Tuples, and If-Else Quiz

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

How do you iterate over a list using a for loop in Python?

a)

for index, value in enumerate(my_list):

b)

for i in range(len(my_list)):

c)

for element in my_list:

d)

for item in my_list:

2.

What is the purpose of a while loop in Python and how is it different from a for loop?

a)

A while loop in Python is used to execute code only once, while a for loop is used for repeated execution

b)

A while loop in Python is used for a specific number of iterations, while a for loop is used for indefinite iterations

c)

The purpose of a while loop in Python is to repeatedly execute a block of code as long as a specified condition is true. It is different from a for loop in that a for loop is used to iterate over a sequence (such as a list) for a specific number of times.

d)

A while loop in Python is used to iterate over a sequence, while a for loop is used for conditional execution

3.

Define a set in Python and explain its characteristics.

a)

A set in Python allows duplicate elements.

b)

A set in Python is an unordered collection of unique elements. It does not allow duplicate elements and is mutable.

c)

A set in Python is an ordered collection of unique elements.

d)

A set in Python is immutable.

4.

What is a dictionary in Python and how is it different from a list?

a)

A dictionary in Python is a collection of key-value pairs, where each key is unique. It is different from a list in that dictionaries are ordered collections of items accessed by index, while lists are unordered collections accessed by keys.

b)

A dictionary in Python is a collection of key-value pairs, where each key is unique. It is different from a list in that dictionaries are unordered collections of items accessed by index, while lists are ordered collections accessed by keys.

c)

A dictionary in Python is a collection of key-value pairs, where each key is unique. It is different from a list in that dictionaries are ordered collections of items accessed by keys, while lists are unordered collections accessed by index.

d)

A dictionary in Python is a collection of key-value pairs, where each key is unique. It is different from a list in that lists are ordered collections of items accessed by index, while dictionaries are unordered collections accessed by keys.

5.

Explain the concept of tuples in Python and provide examples of when to use them.

a)

Tuples can be modified after creation

b)

Tuples are used for looping in Python

c)

Tuples are used when you need an immutable collection of elements, like storing coordinates or database records.

d)

Tuples are only used for storing single values

6.

Explain the concept of list comprehension in Python and provide examples of when to use it.

a)

List comprehension is used to create new lists by applying an expression to each element of an existing list.

b)

List comprehension is used to modify existing lists directly without creating new ones.

c)

List comprehension is used to iterate over dictionaries in Python.

d)

List comprehension is used to perform mathematical operations on lists.

7.

What is the purpose of the 'break' statement in Python loops and how does it differ from the 'continue' statement?

a)

The 'break' statement is used to skip the current iteration and move to the next one, while the 'continue' statement is used to exit the loop completely.

b)

The 'break' statement is used to exit the loop completely, while the 'continue' statement is used to skip the current iteration and move to the next one.

c)

The 'break' statement is used to restart the loop from the beginning, while the 'continue' statement is used to exit the loop completely.

d)

The 'break' statement is used to skip the current iteration and move to the next one, while the 'continue' statement is used to restart the loop from the beginning.

8.

Which of the following is a valid way to access the value associated with a specific key in a dictionary in Python?

a)
my_dict.get('specific_key')
b)
my_dict[specific_key]
c)
my_dict('specific_key')
d)
my_dict['specific_key']
9.

What is the in operator used for in python?

a)
Used to define a new function
b)
Used to perform mathematical operations
c)
Used to determine the data type of a variable
d)
Used to check if a value exists in a sequence
10.

What is the result of 5 + 3 * 2?

a)
11
b)
7
c)
13
d)
10