Quizzes

Python Functions Quiz


Welcome to the Python Functions Quiz!

Functions are a fundamental part of Python that help make code reusable, readable, and modular. This quiz will test your knowledge of Python functions, including syntax, arguments, return values, scope, built-in functions, and more.

Table of Contents:


Functions Quiz


Quiz Questions

1. What is the correct way to define a function in Python?
a) function my_func():
b) def my_func:
c) def my_func():
d) create function my_func()

2. What keyword is used to exit a function and return a value?
a) exit
b) stop
c) return
d) break

3. What will be the output of the following code?

def add(a, b):
return a + b

print(add(2, 3))

a) 2 + 3
b) 5
c) None
d) Error

4. What will be the output of this code?

def my_func(x=5):
return x * 2

print(my_func())

a) 10
b) 5
c) None
d) Error

5. What is the default return value of a function that does not explicitly return a value?
a) 0
b) None
c) False
d) Empty String

6. Which of the following is NOT a valid function name?
a) def _my_func():
b) def 2nd_function():
c) def myFunc():
d) def func_123():

7. What is the correct way to call a function named greet?
a) call greet()
b) greet()
c) run greet()
d) execute greet()

8. What will be the output of this code?

def my_func(a, b=10):
return a + b

print(my_func(5))

a) 15
b) 10
c) 5
d) Error

9. What does the *args parameter allow in a function?
a) Accepts a fixed number of arguments
b) Accepts multiple positional arguments
c) Accepts multiple keyword arguments
d) Allows a function to return multiple values

10. What will be the output of this code?

def multiply(a, b=2):
return a * b

print(multiply(3, 4))

a) 12
b) 6
c) 8
d) Error

11. What does **kwargs do in a function?

a) Accepts multiple positional arguments
b) Accepts multiple keyword arguments
c) Accepts a fixed number of arguments
d) Throws an error if extra arguments are passed

12. What will be the output of this function call?

def example(x, y=5):
return x + y

print(example(3, y=7))

a) 10
b) 8
c) 15
d) Error

13. What is a lambda function?
a) A function with multiple return values
b) A function with no arguments
c) A small anonymous function
d) A function that modifies global variables

14. What is the output of this lambda function?

square = lambda x: x * x
print(square(4))

a) 8
b) 16
c) 4
d) Error

15. What is the correct way to pass an arbitrary number of keyword arguments?
a) def func(**kwargs):
b) def func(*kwargs):
c) def func(***kwargs):
d) def func($kwargs):

16. Which statement about Python functions is TRUE?
a) Functions must always return a value
b) A function can modify global variables without the global keyword
c) Functions can have multiple return statements
d) Functions cannot accept multiple arguments

17. What will be the output of the following code?

def outer():
x = 10
def inner():
return x + 5
return inner()

print(outer())

a) 15
b) 10
c) 5
d) Error

18. What is recursion in Python?
a) A function calling itself
b) A function returning multiple values
c) A function modifying global variables
d) A function taking no parameters

19. What will happen if a recursive function doesn’t have a base case?
a) It will run indefinitely and cause an error
b) It will return None
c) It will stop after 10 iterations
d) It will throw a syntax error

20. What does the global keyword do in Python?
a) Declares a variable as immutable
b) Allows a function to access a global variable
c) Restricts a function from modifying a variable
d) Creates a local variable


How did you do? 🎯

  • 18-20 correct → 🏆 Excellent! You’re a Python functions pro!
  • 14-17 correct → 👍 Great job! Keep practicing.
  • 10-13 correct → 🙂 Good, but there’s room for improvement.
  • Below 10 → 🤔 No worries! Review the concepts and try again.

by AICorr Team

We are proud to offer our extensive knowledge to you, for free. The AICorr Team puts a lot of effort in researching, testing, and writing the content within the platform (aicorr.com). We hope that you learn and progress forward.