1. Home
  2. Data Science
  3. Python
  4. What does a docstring do in Python?

Added 25 Nov 2026

What does a docstring do in Python?

  1. Documents a module, class or function and is available through __doc__ Correct answer
  2. Executes code before the function
  3. Imports documentation
  4. Hides the function

Correct answer

A. Documents a module, class or function and is available through __doc__

MCQSEXAM

Explanation

The first string literal in a function body becomes its __doc__ attribute.

Reference

Asked in: Python Interview Functions

https://docs.python.org/3/tutorial/controlflow.html#defining-functions

Preparing for an exam?

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