Python

Docstrings & Documentation

10 flashcards · answers and spaced-repetition review in the KnowCard app

Will this become the function's docstring? ``` def f(): x = 1 """Do nothing.""" return x ```
What does this print? ``` def f(): # Adds two numbers pass print(f.__doc__) ```
A teammate says the only difference between a docstring and a # comment is style. What's the real difference?
Where must a module-level docstring go for module.__doc__ to return it?
Which built-in function turns an object's docstrings into a formatted help page in the interactive shell?
Per PEP 257, what's the convention for the FIRST line of a multi-line docstring?
Name the three common docstring formats and one tool that consumes docstrings.
By default pydoc time just prints text to the terminal (like help()). How do you instead (a) save an HTML file and (b) browse all modules in a web browser?
You want pydoc to document (a) the whole time module, (b) a script at ./util.py, and (c) only time.sleep. How do you invoke each — and why might pydoc mymod fail even though mymod.py exists somewhere on disk?
A reviewer says "follow PEP 8 and PEP 257." Which one governs code formatting and which governs docstrings — and does the interpreter enforce them?

Start learning today

Free to start — download the app or use it in your browser.

Get it on App StoreGet it on Google Play
Docstrings & Documentation (Python) · KnowCard