Font size
Worksheets[Quiz] Python Function
Total questions: 12
Worksheet time: 8mins
What is the correct syntax for defining a function in Python?
def function_name:
function function_name():
define function_name()
def function_name():
What does the return statement do in a function?
It ends the function and sends a value back.
It defines the input parameters of a function.
It prints the output to the console.
It loops through the function.
Parameters are values passed to a function when it is called.
True
False
Given the function:
def greet(name):
return "Hello, " + name
What will greet("Alice") output?
Hello, Alice
Hello, name
"Hello, Alice"
Alice
Which variable is accessible both inside and outside of functions?
Local variable
Global variable
Input variable
Parameter variable
Variables defined inside a function have a local scope.
True
False
Write a function named add_two_numbers that takes two parameters, a and b, and returns their sum.
(a)
Which of the following is an example of a built-in Python function?
def()
add()
print()
subtract()
A variable defined outside any function has a (a) scope.
Write a function named square that takes one parameter, n, and returns the square of n.
(a)
All functions must have a return statement.
True
False
What is the output of this function if called as hello_world()?
def hello_world():
return "Hello, world!"
Hello, world!
hello_world
Hello world
