Learn with Yasir

Share Your Feedback

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?

def my_func(a, b, c=3):
    return a + b + c
  • 🟢 A. my_func(1, 2)
  • 🔵 B. my_func(1, 2, 4)
  • 🟠 C. my_func(a=1, b=2, c=5)
  • 🔴 D. my_func(1, c=4, b=2, 5)
Answer

my_func(1, c=4, b=2, 5)

Positional arguments cannot follow keyword arguments.


Q3. What is the output of the following code?

def greet(name: str) -> str:
    return "Hello, " + name + "!"
result = greet(5)
print(result)
  • 🟢 A. Hello, 5!
  • 🔵 B. TypeError
  • 🟠 C. None
  • 🔴 D. Hello, !
Answer

Hello, 5!

Type hints are not enforced at runtime by default; 5 is converted to a string.


🔴 Advanced

🧠 Practice & Progress

Explore More Topics

📘 Learn Python

Tutorials, Roadmaps, Bootcamps & Visualization Projects

Python Fundamentals

Flow Control Statements


Python Functions


Fundamentals more ...




🧠 Python Advanced

Object-Oriented Programming in Python (OOP)

More...

🧠 Modules