Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Mastering Python Fundamentals

Total questions: 18

Worksheet time: 9mins

Name
Class
Date
1.

What is type conversion in Python?

a)

Type conversion refers to the process of optimizing code performance.

b)

Type conversion in Python is the process of converting one data type to another.

c)

Type conversion is the process of changing variable names.

d)

Type conversion is a method for debugging errors in Python.

2.

How do you write a single-line comment in Python?

a)

/* This is a comment */

b)

# This is a single-line comment

c)

// This is a comment

d)

# This is not a comment

3.

Explain the input, processing, and output model in programming.

a)

Output is the data that is not used in the program.

b)

Processing is only about storing data.

c)

The input, processing, and output model describes the flow of data in a program: input (data received), processing (data manipulation), and output (result produced).

d)

Input is the final result of a program.

4.

What is the syntax for an if-else statement in Python?

a)

if (condition) { do_something } else { do_something_else }

b)

if condition do_something else do_something_else

c)

if condition: do_something; else do_something_else

d)

if condition: do_something else: do_something_else

5.

How do you create a nested if statement?

a)

if (condition1) { // code to execute }

b)

if (condition1) { if (condition2) // code to execute }

c)

if (condition1 && condition2) { // code to execute }

d)

if (condition1) { if (condition2) { // code to execute if both conditions are true } }

6.

What is the purpose of the elif statement?

a)

The elif statement is used to check additional conditions in an if-else structure.

b)

The elif statement is used to define functions.

c)

The elif statement is used to create loops.

d)

The elif statement is used to terminate a program.

7.

Describe the structure of a while loop in Python.

a)

for condition: # code to execute

b)

while condition: # code to execute

c)

repeat until condition: # code to execute

d)

do while condition: # code to execute

8.

How does a for loop differ from a while loop?

a)

A for loop iterates a known number of times, while a while loop continues until a condition is false.

b)

A for loop requires a condition to be true, while a while loop does not need any conditions.

c)

A for loop runs indefinitely, while a while loop stops after a set number of iterations.

d)

A for loop is used for conditional statements, while a while loop is used for iteration.

9.

What are nested loops and when would you use them?

a)

Nested loops can only be used with one-dimensional arrays.

b)

Nested loops are used to iterate over multi-dimensional data structures or to perform operations involving combinations of elements.

c)

Nested loops are a type of data structure.

d)

Nested loops are only used for sorting data.

10.

What is the function of the break statement in loops?

a)

The break statement terminates the loop execution.

b)

The break statement skips the current iteration of the loop.

c)

The break statement pauses the loop execution.

d)

The break statement continues to the next loop iteration.

11.

How does the continue statement work in loops?

a)

The continue statement skips the current loop iteration and continues with the next one.

b)

The continue statement pauses the loop for a specified time.

c)

The continue statement restarts the loop from the beginning.

d)

The continue statement ends the loop immediately.

12.

What are some basic operations you can perform on lists?

a)

Reversing the order of elements

b)

Adding, removing, accessing, slicing, and sorting elements.

c)

Filtering elements by type

d)

Duplicating elements

13.

How do you access elements in a list using indexing?

a)

Access elements by using curly braces, e.g., list{index}.

b)

Use a dot notation, e.g., list.index.

c)

Use square brackets with the index number, e.g., list[index].

d)

Use parentheses with the index number, e.g., list(index).

14.

Explain list comprehension and provide an example.

a)

Example: squares = [x**2 for x in range(10)] results in squares being [0, 1, 4, 9, 16, 25, 36, 49, 64, 81].

b)

Example: doubles = [x*2 for x in range(10)] results in doubles being [0, 2, 4, 6, 8, 10, 12, 14, 16, 18].

c)

Example: cubes = [x**3 for x in range(5)] results in cubes being [0, 1, 8, 27, 64].

d)

Example: evens = [x for x in range(10) if x % 2 != 0] results in evens being [1, 3, 5, 7, 9].

15.

What are the key methods for creating and modifying dictionaries in Python?

a)

append()

b)

Key methods for creating and modifying dictionaries include: using {}, dict(), assignment, del, pop(), and update().

c)

using []

d)

remove()

16.

What is the purpose of the pass statement in Python?

a)

The pass statement is used to create an empty function or class.

b)

The pass statement is used to terminate a program.

c)

The pass statement is used to raise exceptions.

d)

The pass statement is used to skip the current iteration of a loop.

17.

How can you merge two dictionaries in Python?

a)

Using the append() method.

b)

Using the merge() method.

c)

Using the update() method or the {**d1, **d2} syntax.

d)

Using the join() method.

18.

What is the difference between a list and a tuple in Python?

a)

Lists can only contain strings, while tuples can contain any data type.

b)

Lists are mutable, while tuples are immutable.

c)

Lists are faster than tuples in all cases.

d)

Lists are defined using parentheses, while tuples are defined using square brackets.