wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python

Total questions: 15

Worksheet time: 3mins

Name
Class
Date
1.

What is the purpose of the 'lambda' function in Python?

a)

To create anonymous functions

b)

To create named functions

c)

To create classes

d)

To create modules

2.

What does the 'with' statement in Python ensure?

a)

Proper indentation

b)

Proper error handling

c)

Proper resource management and file closure

d)

Proper variable assignment

3.

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

a)

string = """Line 1 \n Line 2"""

b)

string = 'Line 1 \n Line 2'

c)

string = 'Line 1 + Line 2'

d)

string = 'Line 1 \ Line 2'

4.

What is the output of this code?

a)

15

b)

100000

c)

50

d)

100

5.

In Python, what is the purpose of a 'docstring'?

a)

To include a document file in the code

b)

To provide documentation within a function or module

c)

To declare a variable that stores text data

d)

To encrypt code for security

6.

What is the purpose of the 'pass' statement in Python?

a)

To terminate a loop

b)

To raise an exception

c)

To skip a conditional block

d)

To create an empty function or class

7.

What is the output of this code?

a)

1

2

3

4

5

b)

1 3 5

c)

1

3

5

d)

1

2

4

5

8.

In Python, what does the 'zip( )' function do?

a)

Combines two dictionaries

b)

Iterates over two or more lists simultaneously

c)

Compresses a file

d)

Returns the quotient and remainder of division

9.

 What will be printed when this code is executed?

a)

8

b)

15

c)

3

d)

5

5

5

10.

What is a decorator in Python?

a)

A design pattern for user interfaces

b)

A module for data visualization

c)

A function that modifies the behavior of another function

d)

A graphical element in a GUI application

11.

How do you open a file named "data.txt" in read mode in Python?

a)

file = open("data.txt", "r")

b)

file = open("data.txt", "read")

c)

file = read_file("data.txt")

d)

file = open("data.txt")

12.

What will be printed when this code is executed?

a)

APPLE

banana

CHERRY

b)

apple

banana

cherry

c)

Apple

Banana

Cherry

d)

APPLE

BANANA

CHERRY

13.

What is the output of this code?

a)

5 4 3 2 1

b)

5

4

3

2

1

c)

1

2

3

4

5

d)

1 2 3 4 5

14.

What will be the output when this code is executed?

a)

1

2

3

4

5

b)

2

4

c)

1 3 5

d)

1

3

5

15.

What will be printed when this code is executed?

a)

0

1

2

3

4

b)

0

2

4

6

8

10

c)

0

2

4

6

8

d)

none