There's more...

dir() in particular is extremely useful for inspecting unknown objects, modules, or classes. If you need to filter out the default attributes, and clarify the output, you can filter the output this way:

>>> [att for att in dir(dictionary) if not att.startswith('__')]
['clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']

In the same way, if you're searching for a particular method (such as something that starts with set), you can filter in the same way.

help() will display the docstring of a function or class. docstring is the string defined just after the definition to document the function or class:

>>> def something():
... '''
... This is help for something
... '''
... pass
...
>>> help(something)
Help on function something in module __main__:

something()
This is help for something

Notice how in the next example, the  This is help for something string is defined just after the definition of the function.

docstring is normally enclosed in triple quotes to allow writing string with multiple lines. Python will treat everything inside triple-quotes as a big string, even if there are newlines. You can use either ' or " characters,  as long as you use three of them. You can find more information about docstrings at https://www.python.org/dev/peps/pep-0257/.

The documentation for the built-in functions can be found at https://docs.python.org/3/library/functions.html#built-in-functions, and the full documentation for pprint can be found at https://docs.python.org/3/library/pprint.html#.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.184.66