Python Functions MCQs – Multiple Choice Questions for Practice and Learning
Test and improve your understanding of Python functions with these multiple choice questions. Practice function definitions, parameters, arguments, return statements, and more with beginner-friendly MCQs and detailed answers. Ideal for students and Python learners.
Topic: functions
📝 Multiple Choice Questions
🟢 Beginner
Q1. What is the output of the following code?
def greet(name="User"):
return "Hello, " + name
print(greet("Ahmad"))
🟢 A. Hello, User
🔵 B. Hello, Ahmad
🟠 C. Hello
🔴 D. Error
Answer
Hello, Ahmad
The function is called with 'Ahmad', overriding the default value 'User'.
Q2. What is the output of the following code?
def my_function():
pass
print(my_function())
🟢 A. None
🔵 B. 0
🟠 C. True
🔴 D. Error
Answer
None
Functions without a return statement return None by default.
Q3. What is the output of the following code?
def my_func(a, b=2, c=3):
return a + b + c
print(my_func(5, c=4))
🟢 A. 11
🔵 B. 12
🟠 C. 10
🔴 D. Error
Answer
11
a=5, b=2 (default), c=4 (passed), so 5+2+4=11.
Q4. What is the output of the following code?
def change_value(x):
x = 10
num = 5
change_value(num)
print(num)
🟢 A. 5
🔵 B. 10
🟠 C. Error
🔴 D. None
Answer
5
Integers are immutable; changing x inside the function doesn't affect the original variable.
Q5. What will be the output of this code?
def func(x, y=2):
return x * y
print(func(3))
🟢 A. 2
🔵 B. 6
🟠 C. 3
🔴 D. Error
Answer
6
x=3, y=2 (default), so result is 3*2=6.
Q6. What is the main purpose of a function in Python?
🟢 A. To group a set of related code into a single unit
🔵 B. To create a new type of data
🟠 C. To write a program in a single line
🔴 D. To change the value of global variables
Answer
To group a set of related code into a single unit
Functions help in organizing code and improving reusability.
Q7. What is the purpose of the return statement in a function in Python?
🟢 A. To print the output of the function
🔵 B. To exit the function and return a value
🟠 C. To execute the function without returning anything
🔴 D. To stop the function and start a new one
Answer
To exit the function and return a value
The return statement ends function execution and optionally passes a value back.
Q8. What is the correct way to define a function in Python?
🟢 A. function my_function():
🔵 B. def my_function():
🟠 C. define my_function():
🔴 D. my_function() {
Answer
def my_function():
Functions are defined using the def keyword in Python.
Q9. What happens if you don't include a return statement in a function?
🟢 A. The function will return None.
🔵 B. The function will cause an error.
🟠 C. The function will return 0.
🔴 D. The function will return the last variable used.
Answer
The function will return None.
Functions return None by default if no return statement is provided.
🟡 Intermediate
Q1. What is the output of the following code?
def myfunction(val):
return val % 4 == 0
print(myfunction(13) or myfunction(8))
🟢 A. 0
🔵 B. 13
🟠 C. False
🔴 D. True
⚪ E. 3.5
Answer
True
myfunction(13) returns False, myfunction(8) returns True, and False or True evaluates to True.
Q2. Which of the following function calls is invalid for this function definition?