Question:

Which of the following is used to define a function in Python?

Show Hint

In Python, use the `def` keyword to define functions. This is followed by the function name and parameters.
  • def
  • function
  • func
  • define
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

Step 1: Understanding the Python syntax for defining a function.
In Python, the keyword `def` is used to define a function. The syntax is: \[ \texttt{def function_name():} \] This is followed by the function's code block.
Step 2: Evaluating the options.
  • (A) def: Correct. In Python, `def` is the keyword used to define functions.
  • (B) function: Incorrect. `function` is not a valid keyword in Python to define a function.
  • (C) func: Incorrect. `func` is not a Python keyword used for defining functions.
  • (D) define: Incorrect. `define` is not a valid keyword in Python to define a function.

Step 3: Conclusion.
The correct answer is (A) `def`, as it is the correct keyword used to define functions in Python. Final Answer:} def.
Was this answer helpful?
0
0