Questions tagged [docstring]

A docstring is a string that occurs as the first statement in a module, function, class, or method definition, and is used to document the object in which it occurs.

A docstring is a string that occurs as the first statement in a module, function, class, or method definition, and is used to document the object in which it occurs.

For example, this Python module:

"""shibboleth.py - answer a common interview question with style and grace."""

DEFAULTS = (
    (3, "Fizz"),
    (5, "Buzz"),
)


def fizzbuzz(limit=15, sep=" ", **kwargs):
    """Print from 1 to `limit`, replacing as in the childhood game."""
    transform = sorted((v, k) for k, v in kwargs.items()) or DEFAULTS
    for number in range(1, limit + 1):
        matches = (word for factor, word in transform if number % factor == 0)
        print(sep.join(matches) or number)

... contains two docstrings: a module-level docstring which contains the filename of the module and a brief description of its purpose, and a function-level docstring which describes the behaviour of the function in which it occurs.

Conventions for writing Python docstrings can be found in PEP 257: Docstring Conventions.

Info on docstrings in other languages than Python can be found on Wikipedia.

745 questions
-1
votes
1 answer

How to indicate a return type that is nested (e.g. a list of ints)

I have a python function with nested return types, how can I indicate the return types correctly? (For example pycharm might detect the return type as Tuple[list, int, int] where every type is linked individually) e.g. def random_list(num): …
Mark Omo
  • 898
  • 2
  • 12
  • 26
-1
votes
1 answer

Why Eclipse Pydev uses @author in default template

I have been intrested for python documenting for a while but I can't figured out why @author is default sytnax in python templates. Why it isn't :author: (in restructuredtext style)? From what reason is used syntax with @ and not with : I though…
-2
votes
2 answers

Docstrings parameters to be passed directly to API call

I am writing documentation for my method which has many parameters, but all are just being directly passed into an API call. It will look something like this: def func(a, b, c, d, e, f, g, h): api(a, b, c, d, e, f, g, h) What should I put for…
-2
votes
2 answers

Empty functions/methods with just the docstring valid in Python?

I have the following valid Python code: class A: def __init__(self): """ Some doc-string """ def some_method(self): """ Some other doc-string """ def say(): """ Well that's it, no…
Yash Ranjan
  • 75
  • 1
  • 3
-2
votes
1 answer

vim with python: [missing-function-docstring] Missing function or method docstring

I have vim 9.0 with Python support: I have auto complete and Syntax checking for Python installed. Here is my ~/.vimrc file contents: set nocompatible " required filetype off " required " set the runtime path to…
mad
  • 2,677
  • 8
  • 35
  • 78
-2
votes
1 answer

What does S.find(sub[, start[, end]]) mean?

I'm learning to use python docstring. >>> print(str.find.__doc__) S.find(sub[, start[, end]]) -> int ... When I print str.find() docstring, I don't understand what this means. What does S.find(sub[, start[, end]]) mean?
Radia
  • 3
  • 3
-2
votes
1 answer

Cannot access __doc__ from argparse without redefining it

I have a module in which a define a module __doc__ string (multiline) which I also want to use in my argparse usage. So at first I defined it as '''My multiline module doc-string ''' and used it in the following way parser =…
Nemelis
  • 4,858
  • 2
  • 17
  • 37
-3
votes
1 answer

Adding docstring under my function seems to alter my result

I'm adding a docstring under my function just to see what's going to happen. When I run it, it returns the docstring instead of my function result. I thought docstring just like the comment that won't affect my result. Remove the docstring and my…
Guacaka283
  • 83
  • 6
-3
votes
1 answer

docstrings into xml format

I need to convert docstrings into XML data and append this XML data in the begining of the already existing XML file. Data to convert into XML looks something like this: """ Sample Description: Sample author: abc sample version: x.1 multiple lines…
user1116309
  • 91
  • 1
  • 4
-5
votes
1 answer

Python - how to use docstring and code examples of a function

def sum_prime(): digit_Sum([1, 2, 3]) == 1 + 2 + 3 = 6 digit_Sum([5, 6, 7]) == 5 + 6 + 7 = 18 digit_Sum([100, 12, 1]) == 1 + 0 + 1 + 0 + 2 + 1 = 5 **The digit sum function should return the sum of all the digits in a given list of integers. what is…
Hany
  • 3
  • 3
1 2 3
49
50