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

Which sys module function/attribute is commonly used to exit a Python script programmatically
sys.exit() is listed twice
Hello,
Question 2: To prevent the code from running when imported as a module. Isn’t it the correct answer?
This function does NOT return a value:
def infinite_loop():
while True:
pass
infinite_loop() # no value returned (no matter how long I wait)
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.
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.
How the 3rd Question
Option no which one is correct?
Can anyone explain me.
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.
yup i did answer with false and get confused why they said it’s true
If no return statement called inside the function then it will return default value as None. So the function will always return the value
thanks a lot for describing
this answer
1234
error in line number 3 . It should be “i” not n
Thank for this website.
Q4 the first option “A Python function can return only a single value” should be True.
Hi folks
Hi
print(77)Really helpful for me.Thanks a lot…
This quiz on **Python functions** was very useful. Thanks a lot.
Q No 7. A function cannot return multiple values, it always returns single value.
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
In that case you are returning a Tuple, so, it is a single value
Question 9 why emp and salary why not Kelly and 9000
it is what it is
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()
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?
Hi Cristina, Pass is a statement it has nothing to do with the return value.
Allways returns a value. None is returned in this case. None –>
def fun(): pass# give True
fun() == NoneHi,
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!
I have a question about a code.
# Replace this starter code with your function
How to rewrite functions?
def june_days(self, days):self.days = days
june_days = 30
print("June has " + str(june_days) + " days.")
Thank you for the exercise and great afford by the way. I have an exam on Friday “phase test of python”.let see..
Thank you a lot. The knowledge that you have brought to us has been very useful.
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!
Thanks a lot man, for your great efforts … <3
this was really helpful 🙂
I think for question number 5
both
fun1(name=’Emma’, age=23)andfun1(‘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
Hey Poorna, Yes, you are right. Now I have updated the quiz
I agree with both Rohan and Suman; but, for me, the question number is 6.
Q9 is wrong.
It should be
displayPerson("Emma",25). Current code throws error and explanation talk aboutkwargsinstead of “args”.Hi Rohan, Thank you for suggesting the correction. we have updated it now.
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.
Q7 has also an answer is correct.
displayPerson("Emma", 25)it is also correct.