Python Functions Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q1
What keyword is used to define a function in Python?
  • A function
  • B def
  • C define
  • D func
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?
  • A break
  • B return
  • C exit
  • D end
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))
  • A <class "lambda">
  • B <class "function">
  • C <class "object">
  • D <class "type">
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?
  • A function my_func():
  • B def my_func():
  • C define my_func():
  • D func my_func():
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?
  • A A function without a name
  • B A function that can only take one argument
  • C A function that returns lambda
  • D A special type of class
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?
  • A 0
  • B None
  • C False
  • D An empty string
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?
  • A anonymous
  • B lambda
  • C def
  • D func
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?
  • A To accept keyword arguments
  • B To accept variable-length positional arguments
  • C To accept only integer arguments
  • D To make arguments optional
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?
  • A Accepts only required arguments
  • B Accepts variable-length keyword arguments
  • C Accepts only string arguments
  • D Accepts dictionary as input
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?
  • A lambda x: x + 1
  • B lambda (x): x + 1
  • C def lambda x: x + 1
  • D function lambda x: x + 1
Answer: Option A
Explanation: Lambda functions use the syntax: lambda parameters: expression
Questions and Answers for Competitive Exams Various Entrance Test