Which of the following is a valid way to define a function in Python?
-
A
def function_name:
-
B
function function_name():
-
C
define function_name():
-
D
def function_name():
Correct answer
Correct answer
D. def function_name():
19 views
Explanation
In Python, a function is defined using the 'def' keyword, followed by the function name and parentheses. The correct syntax is shown in option 'd'.
Doubts & discussion
Not sure why the answer is D? Ask here and get an explanation.
Ask a doubt about this MCQ