Python MCQs Function

Q1. What is a function in Python?

A) A variable
B) A block of reusable code
C) A data type
D) A loop
✅ Correct Answer: (B) A block of reusable code
📘 Explanation: A function is a reusable block of code that performs a specific task.

Q2. Which keyword is used to define a function in Python?

A) func
B) def
C) function
D) define
✅ Correct Answer: (B) def
📘 Explanation: The def keyword is used to define a function.

Q3. What is the correct syntax to define a function?

A) function myFunc():
B) def myFunc[]:
C) def myFunc():
D) define myFunc():
✅ Correct Answer: (C) def myFunc():
📘 Explanation: Functions are defined using def function_name():

Q4. Which statement is used to return a value from a function?

A) output
B) print
C) return
D) yield
✅ Correct Answer: (C) return
📘 Explanation: return sends a value back to the caller.

Q5. What is the output of the following code?

def add(): return 5 + 3 print(add())


A) 5
B) 8
C) add
D) Error
✅ Correct Answer: (B) 8
📘 Explanation: The function returns 8, which is printed.

Q6. Which type of function does not return a value?

A) User-defined
B) Built-in
C) Void function
D) Lambda
✅ Correct Answer: (C) Void function
📘 Explanation: Void functions do not return any value explicitly.

Q7. Which of the following is a built-in Python function?

A) input()
B) myFunc()
C) userFunc()
D) custom()
✅ Correct Answer: (A) input()
📘 Explanation: input() is a built-in Python function.

Q8. How many values can a Python function return?

A) Only one
B) Only two
C) Any number
D) None
✅ Correct Answer: (C) Any number
📘 Explanation: Python functions can return multiple values as tuples.

Q9. What is the output of the following code?

def show(x): print(x) print(show(10))


A) 10
B) None
C) Error
D) show
✅ Correct Answer: (B) None
📘 Explanation: The function prints 10 but returns None.

Q10. What are function parameters?

A) Output values
B) Values passed to function definition
C) Values returned
D) Variables inside function only
✅ Correct Answer: (B) Values passed to function definition
📘 Explanation: Parameters are variables defined in the function header.

Q11. What are arguments in Python functions?

A) Values passed during function call
B) Variables inside function
C) Returned value
D) Keywords
✅ Correct Answer: (A) Values passed during function call
📘 Explanation: Arguments are the actual values passed to parameters.

Q12. Which function allows anonymous functions?

A) def
B) lambda
C) func
D) anon
✅ Correct Answer: (B) lambda
📘 Explanation: lambda creates small anonymous functions.

Q13. What is the correct syntax for a lambda function?

A) lambda x: x+1
B) def lambda(x)
C) lambda(x){x+1}
D) lambda = x+1
✅ Correct Answer: (A) lambda x: x+1
📘 Explanation: Lambda functions are written as lambda arguments: expression

Q14. What is recursion?

A) Looping
B) Function calling another function
C) Function calling itself
D) Repeating code
✅ Correct Answer: (C) Function calling itself
📘 Explanation: Recursion occurs when a function calls itself.

Q15. Which keyword stops the execution of a function?

A) stop
B) return
C) break
D) exit
✅ Correct Answer: (B) return
📘 Explanation: return ends function execution and sends back a value.

Q16. What is the default return value of a function with no return statement?

A) 0
B) False
C) None
D) Error
✅ Correct Answer: (C) None
📘 Explanation: Python functions return None by default.

Q17. Which of the following is used to pass variable-length arguments?

A) *args
B) **kwargs
C) args
D) params
✅ Correct Answer: (A) *args
📘 Explanation: *args allows passing multiple positional arguments.

Q18. Which of the following is used for keyword arguments?

A) *args
B) **kwargs
C) args
D) params
✅ Correct Answer: (B) **kwargs
📘 Explanation: **kwargs allows passing keyword arguments.

Q19. Which function returns the length of an object?

A) size()
B) length()
C) len()
D) count()
✅ Correct Answer: (C) len()
📘 Explanation: len() returns the number of items in an object.

Q20. Which function is used to get user input?

A) read()
B) scan()
C) input()
D) get()
✅ Correct Answer: (C) input()
📘 Explanation: input() reads input from the user.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top