Python Functions Questions and Answers
Practice ModeShowing 10 of 25 questions
Q1
What keyword is used to define a function in Python?
Answer: Option B
Explanation: The "def" keyword is used to define functions in Python, followed by the function name and parentheses.
Q2
Which of the following is used to return a value from a function?
Answer: Option B
Explanation: The "return" statement is used to exit a function and return a value back to the caller.
Q3
What is the output of: print(type(lambda x: x))
Answer: Option B
Explanation: Lambda functions in Python return a function object, so type() returns <class "function">.
Q4
Which of these is a valid function definition?
Answer: Option B
Explanation: Function definitions in Python use the def keyword, function name, parentheses, and a colon.
Q5
What is a lambda function in Python?
Answer: Option A
Explanation: Lambda functions are small anonymous functions defined with the lambda keyword.
Q6
What is the default return value of a function that doesn"t have a return statement?
Answer: Option B
Explanation: In Python, if a function doesn"t explicitly return a value, it returns None by default.
Q7
Which keyword is used to create an anonymous function?
Answer: Option B
Explanation: The lambda keyword is used to create small anonymous functions in Python.
Q8
What is the purpose of *args in a function definition?
Answer: Option B
Explanation: *args allows a function to accept any number of positional arguments as a tuple.
Q9
What does the **kwargs parameter do in a function?
Answer: Option B
Explanation: **kwargs allows a function to accept any number of keyword arguments as a dictionary.
Q10
Which of these is a correct lambda function?
Answer: Option A
Explanation: Lambda functions use the syntax: lambda parameters: expression