September 2018
Intermediate to advanced
398 pages
11h 32m
English
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 ...
Read now
Unlock full access