Python Functions MCQs | 25 Practice Questions with Answers | CBSE Class 12 Computer Science
Class 12 · Computer Science
Python Functions MCQs
Practice these multiple-choice questions to strengthen your understanding of Python Functions. Click Show Answer to reveal the correct answer and explanation.
Q1. Which of the following is a built-in function in Python?
A. display()
B. print()
C. show()
D. output()
Show Answer
Answer: B. print()
Explanation: print() is a built-in Python function used to display output on the screen.
Q2. Which keyword is used to define a user-defined function in Python?
A. function
B. define
C. def
D. func
Show Answer
Answer: C. def
Explanation: The def keyword is used to define a function in Python.
Q3. Functions available in imported modules are known as:
A. Built-in functions
B. User-defined functions
C. Module functions
D. Recursive functions
Show Answer
Answer: C. Module functions
Explanation: Functions defined in modules such as math and random are called module functions.
Q4. Which statement is used to call a function named display?
A. call display()
B. display()
C. function(display)
D. execute display
Show Answer
Answer: B. display()
Explanation: A function is called by writing its name followed by parentheses.
Q5. What is the term used for the variables written in the function definition?
A. Arguments
B. Parameters
C. Constants
D. Identifiers
Show Answer
Answer: B. Parameters
Explanation: Variables declared in the function definition are called parameters.
Q6. Values supplied while calling a function are called:
A. Parameters
B. Variables
C. Arguments
D. Constants
Show Answer
Answer: C. Arguments
Explanation: Arguments are the actual values passed to a function during a function call.
Q7. Which type of parameter automatically receives a default value if no argument is passed?
A. Positional parameter
B. Local parameter
C. Default parameter
D. Global parameter
Show Answer
Answer: C. Default parameter
Explanation: A default parameter has a predefined value that is used when no argument is provided.
Q8. Which type of arguments are matched according to their position in the function call?
A. Keyword arguments
B. Positional arguments
C. Default arguments
D. Global arguments
Show Answer
Answer: B. Positional arguments
Explanation: Positional arguments are assigned to parameters based on their order.
Q9. Which keyword is used to return a value from a function?
A. print
B. output
C. return
D. break
Show Answer
Answer: C. return
Explanation: The return statement sends a value back to the calling function.
Q10. Which statement about functions is correct?
A. A function can return only one value.
B. A function cannot return any value.
C. A function can return one or more values.
D. A function must always return an integer.
Show Answer
Answer: C. A function can return one or more values.
Explanation: Python functions can return multiple values separated by commas, which are received as a tuple.
Q11. Which statement correctly defines a function in Python?
_______ add(a,b):
return a+b
A. function
B. define
C. def
D. fun
Show Answer
Answer: C. def
Explanation: The def keyword is used to define a user-defined function.
Q12. What will be the output of the following code?
def show():
print("Welcome")
show()
A. show
B. Welcome
C. Error
D. Nothing
Show Answer
Answer: B. Welcome
Explanation: The function show() is called, so it prints Welcome.
Q13. What will be the output of the following code?
def add(a,b):
print(a+b)
add(5,7)
A. 5
B. 7
C. 12
D. Error
Show Answer
Answer: C. 12
Explanation: The function adds the two arguments and prints their sum.
Q14. Which of the following is a valid function definition with a default parameter?
A. def show(name="Aman"):
B. def show(name):
C. def show("Aman"):
D. def show=name:
Show Answer
Answer: A.
Explanation: A default parameter is assigned using the = operator in the function definition.
Q15. What will be the output of the following code?
def show(name="Riya"):
print(name)
show()
A. Riya
B. name
C. Error
D. None
Show Answer
Answer: A. Riya
Explanation: Since no argument is passed, the default value "Riya" is used.
Q16. What will be the output of the following code?
def show(name="Riya"):
print(name)
show("Aman")
A. Riya
B. Aman
C. Error
D. name
Show Answer
Answer: B. Aman
Explanation: The argument passed during the function call overrides the default parameter value.
Q17. What will be the output of the following code?
def add(a,b):
return a+b
x=add(8,4)
print(x)
A. 8
B. 4
C. 12
D. Error
Show Answer
Answer: C. 12
Explanation: The function returns the sum, which is stored in x and printed.
Q18. Which statement is true about the return statement?
A. It always prints the result.
B. It terminates the function and optionally returns a value.
C. It repeats the function.
D. It can be used only in built-in functions.
Show Answer
Answer: B.
Explanation: The return statement ends the execution of a function and sends a value back to the caller.
Q19. Which concept describes the order in which statements and function calls are executed?
A. Scope of variables
B. Flow of execution
C. Recursion
D. Iteration
Show Answer
Answer: B. Flow of execution
Explanation: Flow of execution refers to the sequence in which program statements and function calls are executed.
Q20. Which statement is true about function calls?
A. A function must always be defined before it is called.
B. A function can be called without being defined anywhere.
C. A function cannot call another function.
D. A function can only be called once.
Show Answer
Answer: A.
Explanation: In Python, a function must be defined before it is called during program execution.
Q21. A variable declared inside a function is called a:
A. Global variable
B. Local variable
C. Static variable
D. Constant
Show Answer
Answer: B. Local variable
Explanation: A local variable is created inside a function and can be accessed only within that function.
Q22. Which variable can be accessed from any function in the program?
A. Local variable
B. Temporary variable
C. Global variable
D. Positional variable
Show Answer
Answer: C. Global variable
Explanation: A global variable is declared outside all functions and is accessible throughout the program.
Q23. What will be the output of the following code?
x=10
def display():
print(x)
display()
A. 10
B. Error
C. None
D. x
Show Answer
Answer: A. 10
Explanation: The function accesses the global variable x, so it prints 10.
Q24. What will be the output of the following code?
x=10
def display():
x=20
print(x)
display()
print(x)
A. 20 20
B. 10 20
C. 20 10
D. 10 10
Show Answer
Answer: C. 20 10
Explanation: The variable x inside the function is local, while the global variable x remains unchanged.
Q25. What will be the output of the following code?
def calculate(a,b):
return a+b,a*b
x,y=calculate(4,5)
print(x,y)
A. 9 20
B. (9,20)
C. 20 9
D. Error
Show Answer
Answer: A. 9 20
Explanation: The function returns two values. They are unpacked into variables x and y, which are then printed.
Answer Key
| Q.No. | Answer | Q.No. | Answer | Q.No. | Answer |
|---|---|---|---|---|---|
| 1 | B | 10 | C | 19 | B |
| 2 | C | 11 | C | 20 | A |
| 3 | C | 12 | B | 21 | B |
| 4 | B | 13 | C | 22 | C |
| 5 | B | 14 | A | 23 | A |
| 6 | C | 15 | A | 24 | C |
| 7 | C | 16 | B | 25 | A |
| 8 | B | 17 | C | ||
| 9 | C | 18 | B |
Practice Tips
- Understand the difference between parameters and arguments.
- Remember that default parameters are used only when no argument is passed.
- Practice writing functions that return one value as well as multiple values.
- Revise the difference between local and global variables.
- Understand the flow of execution when one function calls another.
- Know the three types of functions in Python:
- Built-in functions
- Functions defined in modules
- User-defined functions
- Practice output-based questions involving function calls and variable scope, as these are frequently asked in CBSE examinations.