wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

[Quiz] Python Function

Total questions: 12

Worksheet time: 8mins

Name
Class
Date
1.

What is the correct syntax for defining a function in Python?

a)

def function_name:

b)

function function_name():

c)

define function_name()

d)

def function_name():

2.

What does the return statement do in a function?

a)

It ends the function and sends a value back.

b)

It defines the input parameters of a function.

c)

It prints the output to the console.

d)

It loops through the function.

3.

Parameters are values passed to a function when it is called.

a)

True

b)

False

4.

Given the function:

def greet(name):
return "Hello, " + name

What will greet("Alice") output?

a)

Hello, Alice

b)

Hello, name

c)

"Hello, Alice"

d)

Alice

5.

Which variable is accessible both inside and outside of functions?

a)

Local variable

b)

Global variable

c)

Input variable

d)

Parameter variable

6.

Variables defined inside a function have a local scope.

a)

True

b)

False

7.

Write a function named add_two_numbers that takes two parameters, a and b, and returns their sum.

(a)  

8.

Which of the following is an example of a built-in Python function?

a)

def()

b)

add()

c)

print()

d)

subtract()

9.

A variable defined outside any function has a (a)   scope.

10.

Write a function named square that takes one parameter, n, and returns the square of n.

(a)  

11.

All functions must have a return statement.

a)

True

b)

False

12.

What is the output of this function if called as hello_world()?

def hello_world():
return "Hello, world!"

a)

Hello, world!

b)

hello_world

c)

Hello world