Python Functions Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q21
What is a pure function?
  • A A function with no parameters
  • B A function that doesn"t return anything
  • C A function with no side effects and deterministic output
  • D A function that only uses built-in features
Answer: Option C
Explanation: A pure function is a function that always produces the same output for the same input and has no side effects.
Q22
What is a higher-order function?
  • A A function with high complexity
  • B A function that takes or returns another function
  • C A function defined in a high-level module
  • D A function with many parameters
Answer: Option B
Explanation: A higher-order function is a function that takes another function as an argument or returns a function.
Q23
Which built-in function is used to get a list of all attributes and methods of an object?
  • A help()
  • B dir()
  • C attrs()
  • D list()
Answer: Option B
Explanation: The dir() function returns all attributes and methods of the specified object, without the values.
Q24
What is function composition?
  • A Writing functions in a composed manner
  • B Combining functions to create new functions
  • C Documenting functions properly
  • D Creating functions with multiple purposes
Answer: Option B
Explanation: Function composition is combining two or more functions to produce a new function.
Q25
What is the purpose of the map() function?
  • A To create a map of function names
  • B To apply a function to all items in an iterable
  • C To map variables to values
  • D To convert dictionaries to lists
Answer: Option B
Explanation: The map() function applies a given function to each item of an iterable and returns a map object.
Questions and Answers for Competitive Exams Various Entrance Test