Home »
MCQs »
Python MCQs
Amongst which of the following is a proper syntax to create a function in Python?
52. Amongst which of the following is a proper syntax to create a function in Python?
-
def function_name(parameters):
...
Statements
...
-
def function function_name:
...
Statements
...
-
def function function_name(parameters):
...
Statements
...
- None of the mentioned above
Answer: A)
def function_name(parameters):
...
Statements
...
Explanation:
To define a function we follow the syntax mentioned in the answer section. def keyword marks the start of the function header. We start from the def keyword and write the name of the function along with function parameters. Function naming follows the naming rules to write identifiers in Python. Arguments or parameters are passed as function arguments. Function arguments are optional. A colon (:) denotes the end of the function header.
def function_name(parameters):
...
Statements
...