Useless expressions

Ben Finney ben+python at benfinney.id.au
Tue Mar 29 03:35:34 EDT 2016


Steven D'Aprano <steve+comp.lang.python at pearwood.info> writes:

> On Monday 28 March 2016 23:18, BartC wrote:
>
> > (There are also docstrings, but until yesterday I didn't even know
> > they were also expressions. Wikipedia says this:
> > 
> > "Python docstrings appear as a string literal (not an expression) as
> > the first statement following the definition of functions..."
> > 
> > so their status is a little unclear.

Thanks for raising this, Bart.

> I think what Wikipedia means is that you cannot use an expression that
> evaluates to a string as a docstring

I agree. I have edited that section of the article, hopefully it is now
clearer:

    Python

    The common practice, of documenting a code object at the head of its
    definition, is captured by the addition of docstring syntax in the
    Python language.

    The docstring for a Python code object (a module, class, or
    function) is the first statement of that code object, immediately
    following the definition (the 'def' or 'class' statement). The
    statement must be a bare string literal, not any other kind of
    expression. The docstring for the code object is available on that
    code object's '__doc__' attribute.

    […]

    <URL:https://en.wikipedia.org/wiki/Docstring#Python>

-- 
 \         “True greatness is measured by how much freedom you give to |
  `\      others, not by how much you can coerce others to do what you |
_o__)                                               want.” —Larry Wall |
Ben Finney




More information about the Python-list mailing list