Chapter 7: Python Functions — Online MCQ Test
COMPUTER SCIENCE · CLASS 12th · Tamil Nadu State Board
Practice Chapter 7: Python Functions with a free chapter-wise online MCQ test.
This chapter covers: Focusing on modular programming this chapter details defining and calling user functions in Python. It explains function arguments return statements variable scope recursive functi....
AI-generated questions from basic to board-exam level, with instant results and explanations.
Chapter 7: Python Functions — Important Questions & Answers
What is the main advantage of using functions in Python?
- A. They make programs more modular and reusable
- B. They remove the need for variables
- C. They always run faster than normal code
- D. They can only be used in built-in libraries
Answer: A. They make programs more modular and reusable
Functions help break a program into smaller, reusable parts, making the code easier to read and maintain.
Functions help break a program into smaller, reusable parts, making the code easier to read and maintain.
Which keyword is used to define a function in Python?
- A. func
- B. define
- C. def
- D. function
Answer: C. def
In Python, the keyword `def` is used to create a user-defined function.
In Python, the keyword `def` is used to create a user-defined function.
What will the following function return? ```python def square(n): return n * n ``` If `square(5)` is called, what is the output?
- A. 10
- B. 25
- C. 55
- D. Error
Answer: B. 25
The function multiplies the number by itself, so `5 * 5 = 25`.
The function multiplies the number by itself, so `5 * 5 = 25`.
What is the output of the following code? ```python x = 10 def test(): x = 20 print(x) test() print(x) ```
- A. 20 20
- B. 10 20
- C. 20 10
- D. 10 10
Answer: C. 20 10
Inside `test()`, `x` is a local variable with value 20. Outside the function, the global `x` remains 10.
Inside `test()`, `x` is a local variable with value 20. Outside the function, the global `x` remains 10.
What is the output of the following code? ```python def demo(a, b=5): return a + b print(demo(3)) ```
- A. 8
- B. 15
- C. 3
- D. Error because `b` is not passed
Answer: A. 8
`b` has a default value of 5, so `demo(3)` becomes `3 + 5 = 8`.
`b` has a default value of 5, so `demo(3)` becomes `3 + 5 = 8`.