Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Functions and Docstrings Quiz

Total questions: 12

Worksheet time: 6mins

Name
Class
Date
1.

What is a function in Python?

a)

A type of variable in Python

b)

A keyword used to define a loop in Python

c)

A built-in module in Python for file input/output operations

d)

A block of reusable code that performs a specific task.

2.

How do you define a function in Python?

a)

def function_name:

b)

function function_name(parameters):

c)

def function_name(parameters): # function body return value

d)

function_name(parameters):

3.

What is the purpose of function parameters?

a)

To pass values into a function for it to perform operations on.

b)

To specify the number of times a function should be executed.

c)

To define the return type of a function.

d)

To receive values from a function for further processing.

4.

How do you specify default values for function parameters?

a)

Use the 'default' keyword in the function declaration.

b)

Specify the default value in a separate variable and pass it as an argument to the function.

c)

Use the 'default' keyword when calling the function.

d)

Assign a value to the parameter in the function declaration.

5.

What does the 'return' statement do in a function?

a)

It terminates the function and returns to the calling function.

b)

It specifies the value that the function should return.

c)

It prints the value of the function to the console.

d)

It assigns a value to a variable within the function.

6.

What is the purpose of function arguments?

a)

To specify the number of times a function can be called.

b)

To define the return type of a function.

c)

To pass values to a function when it is called.

d)

To receive values from a function when it is called.

7.

How do you pass arguments to a function?

a)

By including them inside curly braces when defining the function or when calling the function.

b)

By including them inside square brackets when defining the function or when calling the function.

c)

By separating them with commas when defining the function or when calling the function.

d)

By including them inside the parentheses when defining the function or when calling the function.

8.

What is a docstring in Python?

a)

A built-in function in Python.

b)

A string literal used to document a specific function, method, class, or module.

c)

A type of variable in Python.

d)

A data structure in Python.

9.

How do you write a docstring for a function?

a)

Write a comment at the end of the function definition

b)

Include the docstring as a separate file

c)

Write a string as the first line of the function definition

d)

Use a special keyword to define the docstring

10.

What is the purpose of function documentation?

a)

To hide the implementation details of a function.

b)

To provide information about the purpose, usage, and behavior of a function.

c)

To make the code more readable and maintainable.

d)

To improve the performance of a function.

11.

What is the syntax for calling a function?

a)

functionName{}

b)

functionName[]

c)

functionName()

d)

functionName{}

12.

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

a)

To skip a loop iteration

b)

To terminate a loop

c)

To define a function

d)

To act as a placeholder for code that will be added later