The Python Game Book

code games. learn Python.

User Tools

Site Tools


Sidebar

Github:

en:glossary:d:docstrings

docstring

Python feature

multi-line text inside triple quotes, right after a function or class or module declaration.

docstrings can be read by using the .doc attribute

docstrings can be displayed by advanced editors as help text and can be used for automatic testing.

docstrings follow certain conventions, see

def func(arg1, arg2):
    """Summary line.

    Extended description of function.

    Parameters
    ----------
    arg1 : int
        Description of arg1
    arg2 : str
        Description of arg2

    Returns
    -------
    bool
        Description of return value

    See Also
    --------
    otherfunc : some related other function

    Examples
    --------
    These are written in doctest format, and should illustrate how to
    use the function.

    >>> a=[1,2,3]
    >>> print [x + 3 for x in a]
    [4, 5, 6]
    """
    return True

touch sensor

import time
 
import board
import touchio
 
touch_pad = board.A0  # Will not work for Circuit Playground Express!
# touch_pad = board.A1  # For Circuit Playground Express
 
touch = touchio.TouchIn(touch_pad)
 
while True:
    if touch.value:
        print("Touched!", touch.value)
    time.sleep(0.05)

en/glossary/d/docstrings.txt · Last modified: 2020/10/03 10:47 by horst