Functions In Python — Part 1 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Functions In Python — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you make a parameter optional in a Python function?
Correct Answer: Option B — By providing a default value to the parameter
Detailed Academic Explanation:
In Python, you can make a parameter optional by assigning it a default value in the function definition. When a default value is specified, the parameter becomes optional, and the function can be called without explicitly passing a value for it. For example: def greet(name="Guest"): print(f"Hello, {name}!") Here, the parameter name is optional because it has a default value of "Guest". Note: If no value is provided when the function is called, the default value will be used.
💡Key Conceptual Anchor:Functions In Python
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you pass a variable number of keyword arguments to a function in Python?
Correct Answer: Option A — By using the **kwargs syntax
Detailed Academic Explanation:
Correct Answer: A) By using the **kwargs syntax Keyword Arguments: In Python, keyword arguments are arguments passed to a function along with a name (the keyword) and a value. Example: my_function(name="Alice", age=30) Variable Number of Keyword Arguments: Sometimes, you don't know in advance how many keyword arguments a function might receive. That's where **kwargs comes in. kwargs Explained: * The **kwargs syntax allows a function to accept any number of keyword arguments. * kwargs is just a name (you could technically use another name), but ** is what's important. It tells Python to collect all the keyword arguments into a dictionary. * Inside the function, kwargs acts like a regular dictionary where the keys are the argument names (like "name" and "age") and the values are the corresponding argument values (like "Alice" and 30). Why the other options are incorrect: * Option B ( *args ): Used to pass a variable number of positional arguments. It collects them into a tuple, not a dictionary. * Option C ( * symbol): Used for other purposes such as unpacking iterables or enforcing keyword-only arguments, but not for passing keyword arguments. * Option D ( ... symbol): The ellipsis has special meanings like use in type hints or as a placeholder, but is not related to passing arguments to functions. Therefore, the correct answer is Option A: By using the **kwargs syntax .
💡Key Conceptual Anchor:Functions In Python
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the return statement in a function do?
Correct Answer: Option B — It ends the execution of the function
Detailed Academic Explanation:
It ends the execution of the function is the correct answer to “What does the return statement in a function do”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is NOT a valid function name in Python?
Correct Answer: Option B — 2nd_function
Detailed Academic Explanation:
2nd_function is the correct answer to “Which of the following is NOT a valid function name in Python”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the def keyword in Python?
Correct Answer: Option A — It is used to define a function
Detailed Academic Explanation:
It is used to define a function is the correct answer to “What is the purpose of the def keyword in Python”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the pass statement in a function?
Correct Answer: Option A — It is a placeholder for future code
Detailed Academic Explanation:
It is a placeholder for future code is the correct answer to “What is the purpose of the pass statement in a function”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the lambda keyword do when used in a function?
Correct Answer: Option A — It is used to create anonymous functions (lambda functions)
Detailed Academic Explanation:
It is used to create anonymous functions (lambda functions) is the correct answer to “What does the lambda keyword do when used in a function”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the global keyword do when used in a function?
Correct Answer: Option A — It allows a variable to be modified outside the current scope
Detailed Academic Explanation:
It allows a variable to be modified outside the current scope is the correct answer to “What is the purpose of the global keyword do when used in a function”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the return statement in a function?
Correct Answer: Option C — It ends the execution of the function
Detailed Academic Explanation:
It ends the execution of the function is the correct answer to “What is the purpose of the return statement in a function”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the *args syntax in a function definition mean?
Correct Answer: Option B — It is a reserved keyword in Python
Detailed Academic Explanation:
It is a reserved keyword in Python is the correct answer to “What does the *args syntax in a function definition mean”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of using recursion in a function?
Correct Answer: Option A — It allows a function to call itself
Detailed Academic Explanation:
It allows a function to call itself is the correct answer to “What is the purpose of using recursion in a function”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: def greet(name): print(f"Hello, {name}!") greet("Alice")
Correct Answer: Option A — Hello, Alice!
Detailed Academic Explanation:
Hello, Alice! is the correct answer to “What is the output of the following code: def greet(name): print(f"Hello, {name}!") greet("Alice")”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is a variable defined outside a function referred to as?
Correct Answer: Option B — A global variable
Detailed Academic Explanation:
A global variable is the correct answer to “What is a variable defined outside a function referred to as”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Where are the arguments received from the command line stored?
Correct Answer: Option A — sys.argv
Detailed Academic Explanation:
sys.argv is the correct answer to “Where are the arguments received from the command line stored”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of using the ** symbol in function argument unpacking?
Correct Answer: Option A — It allows a dictionary of arguments to be passed
Detailed Academic Explanation:
It allows a dictionary of arguments to be passed is the correct answer to “What is the purpose of using the ** symbol in function argument unpacking”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? def sum(*args): '''Function returns the sum of all values''' r = 0 for i in args: r += i return r print sum.__doc__ print sum(1, 2, 3) print sum(1, 2, 3, 4, 5)
Correct Answer: Option A — 6 15
Detailed Academic Explanation:
6 15 is the correct answer to “What will be the output of the following Python code? def sum(*args): '''Function returns the sum of all values''' r = 0 for i in args: r += i return r print sum.__doc__ print sum(1, 2, 3) print sum(1, 2, 3, 4, 5)”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? min = (lambda x, y: x if x < y else y) min(101*99, 102*98)
Correct Answer: Option C — 9996
Detailed Academic Explanation:
9996 is the correct answer to “What will be the output of the following Python code? min = (lambda x, y: x if x < y else y) min(101*99, 102*98)”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The nested list undergoes shallow copy even when the list as a whole undergoes deep copy.
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “The nested list undergoes shallow copy even when the list as a whole undergoes deep copy.”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? x = [34, 56] print((''.join(list(map(str, x))),))
Correct Answer: Option D — ('3456',)
Detailed Academic Explanation:
('3456',) is the correct answer to “What will be the output of the following Python code? x = [34, 56] print((''.join(list(map(str, x))),))”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? x = [[0], [1]] print(len(' '.join(list(map(str, x)))))
Correct Answer: Option C — 7
Detailed Academic Explanation:
7 is the correct answer to “What will be the output of the following Python code? x = [[0], [1]] print(len(' '.join(list(map(str, x)))))”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? x = ['ab', 'cd'] print(len(list(map(list, x))))))
Correct Answer: Option C — error
Detailed Academic Explanation:
error is the correct answer to “What will be the output of the following Python code? x = ['ab', 'cd'] print(len(list(map(list, x))))))”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? l1=[1, 2, 3, [4]] l2=list(l1) id(l1)==id(l2)
Correct Answer: Option B — False
Detailed Academic Explanation:
False is the correct answer to “What will be the output of the following Python code? l1=[1, 2, 3, [4]] l2=list(l1) id(l1)==id(l2)”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? def display(b, n): while n > 0: print(b,end="") n=n-1 display('z',3)
Correct Answer: Option A — zzz
Detailed Academic Explanation:
zzz is the correct answer to “What will be the output of the following Python code? def display(b, n): while n > 0: print(b,end="") n=n-1 display('z',3)”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? def foo(fname, val): print(fname(val)) foo(max, [1, 2, 3]) foo(min, [1, 2, 3])
Correct Answer: Option A — 3 1
Detailed Academic Explanation:
3 1 is the correct answer to “What will be the output of the following Python code? def foo(fname, val): print(fname(val)) foo(max, [1, 2, 3]) foo(min, [1, 2, 3])”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? def cube(x): return x * x * x x = cube(3) print x
Correct Answer: Option C — 27
Detailed Academic Explanation:
27 is the correct answer to “What will be the output of the following Python code? def cube(x): return x * x * x x = cube(3) print x”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of a docstring in a function?
Correct Answer: Option A — It provides documentation for the function
Detailed Academic Explanation:
It provides documentation for the function is the correct answer to “What is the purpose of a docstring in a function”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? def f1(): global x x+=1 print(x) x=12 print("x")
Correct Answer: Option D — x
Detailed Academic Explanation:
x is the correct answer to “What will be the output of the following Python code? def f1(): global x x+=1 print(x) x=12 print("x")”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? l1=[10, 20, 30] l2=l1 id(l1)==id(l2) l2=l1.copy() id(l1)==id(l2)
Correct Answer: Option D — True, False
Detailed Academic Explanation:
True, False is the correct answer to “What will be the output of the following Python code? l1=[10, 20, 30] l2=l1 id(l1)==id(l2) l2=l1.copy() id(l1)==id(l2)”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How are keyword arguments specified in the function heading?
Correct Answer: Option C — two stars followed by a valid identifier
Detailed Academic Explanation:
two stars followed by a valid identifier is the correct answer to “How are keyword arguments specified in the function heading”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Fill in the line of the following Python code for calculating the factorial of a number. def fact(num): if num == 0: return 1 else: return _____________________
Correct Answer: Option A — num*fact(num-1)
Detailed Academic Explanation:
num*fact(num-1) is the correct answer to “Fill in the line of the following Python code for calculating the factorial of a number. def fact(num): if num == 0: return 1 else: return _____________________”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? def fun(n): if (n > 100): return n - 5 return fun(fun(n+11)); print(fun(45))
Correct Answer: Option B — 100
Detailed Academic Explanation:
100 is the correct answer to “What will be the output of the following Python code? def fun(n): if (n > 100): return n - 5 return fun(fun(n+11)); print(fun(45))”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? list(map((lambda x:x**2), filter((lambda x:x%2==0), range(10))))
Correct Answer: Option B — [0, 4, 16, 36, 64]
Detailed Academic Explanation:
[0, 4, 16, 36, 64] is the correct answer to “What will be the output of the following Python code? list(map((lambda x:x**2), filter((lambda x:x%2==0), range(10))))”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following code: def my_function(a, b): return a / b result = my_function(4, 2) print(result)
Correct Answer: Option A — 2
Detailed Academic Explanation:
2 is the correct answer to “What will be the output of the following code: def my_function(a, b): return a / b result = my_function(4, 2) print(result)”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? a = [1, 2, 3, 4, 5] b = lambda x: (b (x[1:]) + x[:1] if x else []) print(b (a))
Correct Answer: Option C — []
Detailed Academic Explanation:
[] is the correct answer to “What will be the output of the following Python code? a = [1, 2, 3, 4, 5] b = lambda x: (b (x[1:]) + x[:1] if x else []) print(b (a))”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following statements is false about recursion?
Correct Answer: Option D — Every recursive function must have a return value
Detailed Academic Explanation:
Every recursive function must have a return value is the correct answer to “Which of the following statements is false about recursion”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of these is not true about recursion?
Correct Answer: Option C — Recursive calls take up less memory
Detailed Academic Explanation:
Recursive calls take up less memory is the correct answer to “Which of these is not true about recursion”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? list(map((lambda x:x^2), range(10)))
[2, 3, 0, 1, 6, 7, 4, 5, 10, 11] is the correct answer to “What will be the output of the following Python code? list(map((lambda x:x^2), range(10)))”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of these is false about a package?
Correct Answer: Option B — Each import package need not introduce a namespace
Detailed Academic Explanation:
Each import package need not introduce a namespace is the correct answer to “Which of these is false about a package”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Lambda contains block of statements.
Correct Answer: Option B — False
Detailed Academic Explanation:
False is the correct answer to “Lambda contains block of statements.”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What happens if the base condition isn't defined in recursive programs?
Correct Answer: Option A — Program gets into an infinite loop
Detailed Academic Explanation:
Program gets into an infinite loop is the correct answer to “What happens if the base condition isn't defined in recursive programs”. This question is standard in competitive examination syllabi for Functions In Python.
💡Key Conceptual Anchor:Functions In Python
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.