PYnative

Python Programming

  • Learn Python ▼
    • Python Tutorials
    • Python Basics
    • Python Interview Q&As
  • Exercises ▼
    • Python Exercises
    • C++ Exercises
    • C Programming Exercises
    • Java Exercises
    • C# Exercises
  • Quizzes
  • Online Compilers▼
    • Online Python Code Editor
    • Online C Compiler
    • Online C++ Compiler
    • Online Java Compiler
    • Online C# Compiler
Home » Python » Quizzes » Python Functions Quiz

Python Functions Quiz

Updated on: August 26, 2025 | 43 Comments

Mastering functions and modules is crucial for writing clean, efficient, and scalable Python code. This Python Functions Quiz is designed to test your understanding of two fundamental Python concepts: Functions and Modules.

From defining functions, understanding variable scope and function arguments to importing and utilizing modules, these Multiple Choice Questions (MCQs) will help solidify your knowledge and highlight areas for improvement.

  • The quiz contains 25 questions. There is no time limit.
  • You will get 1 point for each correct answer. Solve 15 correctly to pass the test
  • Read Python functions and Python function arguments for any help.

Also, See:

  • Python Functions Exercise.
  • 15 Python Quizzes: each focusing on a specific topic

1. Which of the following modules is NOT part of Python’s standard library (meaning you usually need to install it separately)?

 
 
 
 

2. What is a key characteristic of a Python generator function?

 
 
 
 

3. One of the main benefits of using modules in Python is:

 
 
 
 

4. What will be the output of the following Python code?

list1 = [1, 2, 3]

def append_item(a_list, item):
    a_list.append(item)

append_item(list1, 4)
print(list1)
 
 
 
 

5. What is the output of the following display() function call

def display(**kwargs):
    for i in kwargs:
        print(i)

display(emp="Kelly", salary=9000)
 
 
 
 

6. What is the output of the following display_person() function call

def display_person(*args):
    for i in args:
        print(i)

display_person(name="Emma", age="25")
 
 
 

7. What is a Python decorator primarily used for?

 
 
 
 

8. Which of the following is the correct way to import only the pi constant from the math module?

 
 
 
 

9. Select which True for Python function

 
 
 
 

10. What is the output of the add() function call

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

result = add(3, 2)
print(result)
 
 
 
 

11. What will be the output of the following Python code?

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

def apply_operation(func, x, y):
    return func(x, y)

result = apply_operation(multiply, 5, 3)
print(result)
 
 
 
 

12. What is the primary purpose of *args and **kwargs in Python function definitions?

 
 
 
 

13. What will be the output of the following Python code?

count = 0

def increment():
    global count
    count += 1

increment()
print(count)
 
 
 
 

14. Choose the correct declaration for fun1().

To enable the successful execution of the below two fun1() function call, choose the correct declaration for fun1().

fun1(25, 75, 55)
fun1(10, 20)
 
 
 
 

15. How would you get the current date and time using the datetime module?

 
 
 

16. What will be the output of the following Python code?

def do_nothing():
    pass

result = do_nothing()
print(result)
 
 
 
 

17. Which function from the random module would you use to get a random integer between 1 and 10 (including 1 and 10)?

 
 
 
 

18. Which of the following best describes a Python lambda function?

 
 
 
 

19. What is the output of the following function call

def add(a, b):
  return a + b
  a = 20
  b = 30
  return a + b

result = add(5, 10)
print(result)
 
 
 
 

20. What will be the output of the following Python code?

numbers = [1, 2, 3, 4, 5]
squared_numbers = list(map(lambda x: x*x, numbers))
print(squared_numbers)
 
 
 

21. What is the output of the following function call

def fun1(name, age=20):
    print(name, age)

fun1('Emma', 25)
 
 
 

22. What is the primary purpose of the if __name__ == "__main__": block in a Python script?

 
 
 
 

23. What is the output of the following code?

def outer_fun(a, b):
    def inner_fun(c, d):
        return c + d
    return inner_fun(a, b)

res = outer_fun(5, 10)
print(res)
 
 
 

24. You want to import the numpy module but refer to it as np in your code. Which syntax is correct?

 
 
 
 

25. What will be the output of the following Python code?

x = 5

def update_x():
    global x
    x = 10

update_x()
print(x)
 
 
 
 

Loading ... Loading …

Loading

Filed Under: Python, Python Basics, Python Quizzes

Did you find this page helpful? Let others know about it. Sharing helps me continue to create free Python resources.

TweetF  sharein  shareP  Pin

About Vishal

I’m Vishal Hule, the Founder of PYnative.com. As a Python developer, I enjoy assisting students, developers, and learners. Follow me on Twitter.

Related Tutorial Topics:

Python Python Basics Python Quizzes

All Coding Exercises:

C Exercises
C++ Exercises
Python Exercises
Java Exercises
C# Exercises

Python Exercises and Quizzes

Free coding exercises and quizzes cover Python basics, data structure, data analytics, and more.

  • 15+ Topic-specific Exercises and Quizzes
  • Each Exercise contains 25+ questions
  • Each Quiz contains 25 MCQ
Exercises
Quizzes

Comments

  1. Brad Kent says

    July 10, 2026 at 2:01 am

    Which sys module function/attribute is commonly used to exit a Python script programmatically

    sys.exit() is listed twice

    Reply
  2. Devaraj says

    February 10, 2026 at 4:08 pm

    Hello,

    Question 2: To prevent the code from running when imported as a module. Isn’t it the correct answer?

    Reply
  3. Kevin says

    April 18, 2025 at 12:17 am

    This function does NOT return a value:

    def infinite_loop():
    while True:
    pass

    infinite_loop() # no value returned (no matter how long I wait)

    Reply
  4. Kevin says

    April 17, 2025 at 12:42 am

    When there is an unhandled error within a function, it looks like the function will not return a value.

    def div(a):
    return 12/a

    b = div(0)
    print(b)

    It looks like code execution stops within the return statement and does not return a value.

    Reply
  5. Gijs says

    June 13, 2024 at 9:17 pm

    Hi Vishal, the question about Python returns is ambiguous. Technically a function always returns exactly *one* object. This is None (of NoneType) by default. This object can be anything, a simple type, like an int, or a container type like a tuple. Combining the return of multiple values (Python will put them in a tuple) with tuple unpacking makes it appear as returning multiple values. The question is ambiguous I think. The term value is not well defined. If you consider value in Python to mean object, the answer should be always exactly one.

    Reply
  6. Pawan Goled says

    May 28, 2023 at 3:19 pm

    How the 3rd Question
    Option no which one is correct?
    Can anyone explain me.

    Reply
  7. sunil sikarwar says

    February 16, 2023 at 2:52 pm

    10. Python function always returns a value

    False
    True
    this question answer should be false because when ll we pass return statement then we get return a value
    otherwise fun don’t return any things.
    so please tell me i m right or wrong.

    Reply
    • hanane says

      July 10, 2023 at 6:17 pm

      yup i did answer with false and get confused why they said it’s true

      Reply
    • Nandhini says

      October 9, 2023 at 1:43 pm

      If no return statement called inside the function then it will return default value as None. So the function will always return the value

      Reply
      • suil says

        November 16, 2023 at 7:42 am

        thanks a lot for describing
        this answer

        Reply
  8. Muthu says

    October 1, 2022 at 9:46 am

    def fun():
    
    for i in range(1,5):
    
    print(n,end=' ')
    
    print (fun())
    Reply
    • Varshith p says

      January 17, 2023 at 12:06 am

      1234

      Reply
    • Ashok Kumar Veerasamy says

      November 30, 2023 at 11:55 pm

      error in line number 3 . It should be “i” not n

      Reply
  9. K says

    June 24, 2022 at 7:44 pm

    Thank for this website.
    Q4 the first option “A Python function can return only a single value” should be True.

    Reply
    • Marq says

      October 17, 2022 at 4:05 pm

      Hi folks

      Reply
      • Djrjr says

        October 17, 2022 at 4:06 pm

        Hi

        print(77)

        Reply
  10. Md Habibur Rahman says

    March 25, 2022 at 8:23 pm

    Really helpful for me.Thanks a lot…

    Reply
  11. THOMAS T V says

    September 16, 2021 at 7:33 am

    This quiz on **Python functions** was very useful. Thanks a lot.

    Reply
  12. Yogesh says

    August 7, 2021 at 5:23 pm

    Q No 7. A function cannot return multiple values, it always returns single value.

    Reply
    • Pramish Mehta says

      October 8, 2022 at 8:52 pm

      No, we can do it. It won’t take multiple return statements. But if you return multiple values with a comma separating them it returns

      Reply
      • Alex says

        February 24, 2024 at 5:25 am

        In that case you are returning a Tuple, so, it is a single value

        Reply
  13. Abdur says

    July 27, 2021 at 11:52 am

    Question 9 why emp and salary why not Kelly and 9000

    Reply
    • elias jemal says

      January 18, 2022 at 1:39 pm

      it is what it is

      Reply
    • Gary says

      July 1, 2026 at 8:24 am

      if you iterate through a dictionary with
      for x in mydict
      then it will only give you the keys
      You can get both keys and values with
      for x in mydict.items()
      or just values with
      for x in mydict.values()

      Reply
  14. Cristina says

    June 8, 2021 at 11:35 pm

    I’m curious about the statement “a function always returns a value”. What about a “pass” statement. Wouldn’t that make the function not return anything? I know stack overflow and all the reading materials say that a function always returns at least None… but what about pass?

    Reply
    • Vishal says

      June 10, 2021 at 4:26 pm

      Hi Cristina, Pass is a statement it has nothing to do with the return value.

      Reply
      • GT says

        December 4, 2021 at 5:33 am

        Allways returns a value. None is returned in this case. None –>

        Reply
      • Rabah says

        March 16, 2023 at 5:37 pm

        def fun(): pass

        # give True
        fun() == None

        Reply
  15. Asha Sarna says

    April 14, 2021 at 2:22 pm

    Hi,

    I noticed that the example used in the explanation of question number 8, had a small error…. shouldn’t the output be Emma, 20 as the default argument was used.

    Great quiz! Keep it up!

    Cheers!

    Reply
  16. ronno says

    April 7, 2021 at 6:33 pm

    I have a question about a code.

    # Replace this starter code with your function

    june_days = 30
    print("June has " + str(june_days) + "days.")
    july_days = 31
    print("July has " + str(july_days) + "days.")

    How to rewrite functions?

    Reply
    • lwaamba says

      February 12, 2023 at 12:41 pm

      def june_days(self, days):
      self.days = days

      june_days = 30
      print("June has " + str(june_days) + " days.")

      Reply
  17. zee says

    February 18, 2021 at 3:45 am

    Thank you for the exercise and great afford by the way. I have an exam on Friday “phase test of python”.let see..

    Reply
  18. long says

    November 23, 2020 at 6:08 pm

    Thank you a lot. The knowledge that you have brought to us has been very useful.

    Reply
  19. Robert says

    September 4, 2020 at 4:02 am

    Your statement “We can pass either use either positional arguments or keyword arguments, not both at the same time.” is not completely true.
    You can mix. You just can not pass a positional argument after a keyword argument, but you can pass a keyword argument after a positional argument.
    So e.g.
    fun1("emma",age=2) works fine.

    Great stuff otherwise, helps me a lot learning Python!

    Reply
  20. Hritik Jaiswal says

    August 30, 2020 at 11:25 pm

    Thanks a lot man, for your great efforts … <3

    Reply
  21. shilpi says

    August 22, 2020 at 8:40 pm

    this was really helpful 🙂

    Reply
  22. poorna says

    August 7, 2020 at 5:05 pm

    I think for question number 5
    both fun1(name=’Emma’, age=23) and fun1(‘Emma’, 23)
    option 1 and 3 is correct. When I marked option 3 alone, while evaluation it shows it’s wrong!

    Also since you have not used ‘ ‘ (quotes) instead ’ ’ symbol is used
    to pass a string, it gives a compilation error !!!

    Hope this helps!!

    Thanks for all your efforts.

    Cheers,
    Poorna

    Reply
    • Vishal says

      August 10, 2020 at 1:29 pm

      Hey Poorna, Yes, you are right. Now I have updated the quiz

      Reply
  23. Enrique says

    July 15, 2020 at 10:45 am

    I agree with both Rohan and Suman; but, for me, the question number is 6.

    Reply
  24. Rohan says

    February 28, 2020 at 2:31 pm

    Q9 is wrong.
    It should be displayPerson("Emma",25). Current code throws error and explanation talk about kwargs instead of “args”.

    Reply
    • Vishal says

      March 4, 2020 at 5:49 pm

      Hi Rohan, Thank you for suggesting the correction. we have updated it now.

      Reply
      • Shayeri says

        August 6, 2020 at 12:58 am

        As I am newbie in programming, I found these quizes really helpful to have a better concept. But I didn’t understand the explanation given for Q2. Some grammatical errors have it very ambiguous.

        Reply
    • Suman says

      April 24, 2020 at 8:13 pm

      Q7 has also an answer is correct.
      displayPerson("Emma", 25) it is also correct.

      Reply

Leave a Reply Cancel reply

your email address will NOT be published. all comments are moderated according to our comment policy.

Use <pre> tag for posting code. E.g. <pre> Your entire code </pre>

In: Python Python Basics Python Quizzes
TweetF  sharein  shareP  Pin

  Python Quizzes

  • 15 Python Quizzes
  • Python Online MCQ Test
  • Basic Quiz For Beginners
  • Variables and Data Types Quiz
  • Functions Quiz
  • if else and loops Quiz
  • Numbers Quiz
  • String Quiz
  • List Quiz
  • Set Quiz
  • Dictionary Quiz
  • Tuple Quiz
  • Operators and Expression Quiz
  • Input and Output Quiz
  • Multithreading and Multiprocessing Quiz
  • File Handling Quiz
  • Random Data Generation Quiz

 Explore Python

  • Python Tutorials
  • Python Exercises
  • Python Quizzes
  • Python Interview Q&A
  • Python Programs

All Python Topics

Python Basics Python Exercises Python Quizzes Python Interview Python File Handling Python OOP Python Date and Time Python Random Python Regex Python Pandas Python Databases Python MySQL Python PostgreSQL Python SQLite Python JSON

About PYnative

PYnative.com is for Python lovers. Here, You can get Tutorials, Exercises, and Quizzes to practice and improve your Python skills.

Follow Us

To get New Python Tutorials, Exercises, and Quizzes

  • Twitter
  • Facebook
  • Sitemap

Explore Python

  • Learn Python
  • Python Basics
  • Python Databases
  • Python Exercises
  • Python Quizzes
  • Online Python Code Editor
  • Python Tricks

Coding Exercises

  • C Exercises
  • C++ Exercises
  • Python Exercises
  • Java Exercises
  • C# Exercises

Legal Stuff

  • About Us
  • Contact Us

We use cookies to improve your experience. While using PYnative, you agree to have read and accepted our:

  • Terms Of Use
  • Privacy Policy
  • Cookie Policy

Copyright © 2018–2026 pynative.com