<jupyter_start><jupyter_text>The Docstring system A docstring is a string literal that occurs as **the first statement** in a package, module or function (method). These structures (Python objects) can be [properly commented](https://www.python.org/dev/peps/pep-0257/) and the documentation processed/retrieved by tools such as  [Sphinx](http://www.sphinx-doc.org/en/1.5/) and `help()`.  1. Example: commenting a class<jupyter_code>class ClassExample():
    '''This first line is a summary of this class. \
There must be ONLY one logical line in this overview.
    
    However (notice that must be an empty line between the summary and this
    block of text), the rest of this doctrings can be placed in several lines.
    These lines usually provides extended information about the functionality
    of the class. The last line of the docstring should contain only
    three simple quotation marks (as follows).
    '''
    
    x = 1
    
    def __init__(self):
        '''A summary about the constructor. This is an example of a one-line docstring.'''
        print(self.x)
        
    def set(self, x):
        '''A summary about \"set\".
        
        Arguments:
            x: an integer that ... bla, bla, bla.
            (Notice the indentation of this/these lines)
            
        Returns:
            Nothing.
        '''
        self.x = x
        
    def get(self):
        '''A summary about \"get\".
        
        Arguments:
            None.
            
        Returns:
            The value of \"x\".
        '''
        return self.x<jupyter_output><empty_output><jupyter_text>2. Using `help()` Getting help for a whole class.<jupyter_code>help(ClassExample)<jupyter_output><empty_output><jupyter_text>A different way of getting help (in Ipython):<jupyter_code>ClassExample?<jupyter_output><empty_output><jupyter_text>Getting help for a single member function:<jupyter_code>help(ClassExample.get)<jupyter_output><empty_output><jupyter_text>`help()` only prints the `__doc__` variable: Any function, class or module starting with a string literal has a non-empty [`__doc__`](https://docs.python.org/3/glossary.htmlterm-docstring) attribute which can be printed to get information.<jupyter_code>print(ClassExample.get.__doc__)
print(type(ClassExample.get.__doc__))<jupyter_output><empty_output><jupyter_text>The same queries can be carried out with an instance.<jupyter_code>a = ClassExample()
help(a)
help(a.set)
print(a.__doc__)
print(a.get.__doc__)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10019880715705766, 'fraction_numerical': 0.003976143141153081, 'mean_word_length': 3.1933333333333334, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '605128', 'license': 'CC0-1.0', 'n_tokens_mistral': 755, 'n_tokens_neox': 734, 'n_words': 241, 'path': '02-basics/14-commenting_code.ipynb', 'repo_name': 'vicente-gonzalez-ruiz/python-tutorial', 'size': '2515'}