1. Home
  2. Data Science
  3. Python
  4. What is the correct way to define a function in Python?

Added 27 Jan 2024

What is the correct way to define a function in Python?

  1. def function_name(parameters): Correct answer
  2. function function_name(parameters):
  3. function function_name = (parameters) => {
  4. void function_name(parameters) {

Correct answer

A. def function_name(parameters):

17 views

MCQSEXAM

Explanation

A Python function is defined with the def keyword: def function_name(parameters):, followed by an indented body. The colon and the indentation are compulsory.

The function keyword and arrow syntax belong to JavaScript, and void name() { } is C, C++ or Java style.

Want more practice? Try the full set of Computer Science MCQs on MCQsExam.com.

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs