filmov
tv
2.2 Python Comments and docstrings

Показать описание
Comments
Python has two ways to annotate Python code. One is by using comments to indicate what some part of the code does. • # is used for single-line comments and are terminated by the end of line. hash followed by a white space or code is commented, but not within string literal. • “”” “”” OR ‘’’ ‘’’ are used for multi-line comments.
Comments
Python has two ways to annotate Python code. • Single-line comments: begin with the hash character ("#") and are terminated by the end of line. • Multi line comments: are achieved by inserting a multi-line string with """ as the delimiter on each end.
Docstrings (documentation strings)
• Docstrings: strings that are located alone without assignment as the first indented line within a module, class, method or function, automatically set their contents as an attribute named __doc__ • Docstrings are intended to store a human-readable description of the object's purpose, behavior, and usage.
• The built-in help function generates its output based on __doc__ attributes. • Such strings can be delimited with " or ' for single line strings, or may span multiple lines if delimited with either """ or '‘’. • Preference is to use triple double quotes (""") for both single and multi-line docstrings.
• Docstrings can be as large as the programmer wants and contain line breaks. It provides documented information about the object. • Docstrings are Python objects and are part of the interpreted Python code. • Running program can retrieve its own docstrings and manipulate that information. Docstrings (documentation strings)
Docstring documentation
There are tools available that can extract the docstrings to generate an API documentation from the code. – Docstring documentation can also be accessed from the interpreter with the help() function, or from the shell with the pydoc command pydoc. – The doctest standard module uses interactions copied from Python shell sessions into docstrings, to create tests.
Python has two ways to annotate Python code. One is by using comments to indicate what some part of the code does. • # is used for single-line comments and are terminated by the end of line. hash followed by a white space or code is commented, but not within string literal. • “”” “”” OR ‘’’ ‘’’ are used for multi-line comments.
Comments
Python has two ways to annotate Python code. • Single-line comments: begin with the hash character ("#") and are terminated by the end of line. • Multi line comments: are achieved by inserting a multi-line string with """ as the delimiter on each end.
Docstrings (documentation strings)
• Docstrings: strings that are located alone without assignment as the first indented line within a module, class, method or function, automatically set their contents as an attribute named __doc__ • Docstrings are intended to store a human-readable description of the object's purpose, behavior, and usage.
• The built-in help function generates its output based on __doc__ attributes. • Such strings can be delimited with " or ' for single line strings, or may span multiple lines if delimited with either """ or '‘’. • Preference is to use triple double quotes (""") for both single and multi-line docstrings.
• Docstrings can be as large as the programmer wants and contain line breaks. It provides documented information about the object. • Docstrings are Python objects and are part of the interpreted Python code. • Running program can retrieve its own docstrings and manipulate that information. Docstrings (documentation strings)
Docstring documentation
There are tools available that can extract the docstrings to generate an API documentation from the code. – Docstring documentation can also be accessed from the interpreter with the help() function, or from the shell with the pydoc command pydoc. – The doctest standard module uses interactions copied from Python shell sessions into docstrings, to create tests.