Functions in Python Quiz - CBSE Class 11 Computer Science
Free practice quiz: Functions in Python (CBSE Class 11 Computer Science). 20 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
Play all 20 questions freeSample questions
What is a function in Python?
- A block of code that performs a specific task
- A type of variable
- A data structure
- A loop
Show answer
Answer: A. A block of code that performs a specific task
A function is a reusable block of code designed to perform a specific task.
What is a function parameter?
- A variable declared inside a function
- The value returned by a function
- A variable in the function definition that receives an argument
- A type of loop
Show answer
Answer: C. A variable in the function definition that receives an argument
Parameters act as placeholders for the arguments passed during function call.
What happens if a recursive function lacks a base case?
- The function executes correctly
- The program crashes
- The function returns an error
- The program enters an infinite loop
Show answer
Answer: D. The program enters an infinite loop
Without a base case, the function will call itself repeatedly without stopping.
How can you access a global variable from inside a function?
- You cannot access global variables from inside a function
- By declaring the variable as 'global' inside the function
- By passing the variable as an argument to the function
- By using the 'global' keyword before accessing the variable
Show answer
Answer: D. By using the 'global' keyword before accessing the variable
Using the 'global' keyword explicitly indicates that you want to modify the global variable.
What is the difference between *args and **kwargs?
- *args accepts keyword arguments, **kwargs accepts positional arguments
- *args accepts a variable number of positional arguments, **kwargs accepts a variable number of keyword arguments
- Both are the same
- *args is used for recursion, **kwargs for iteration
Show answer
Answer: B. *args accepts a variable number of positional arguments, **kwargs accepts a variable number of keyword arguments
They are used to handle flexible function signatures.