August 2019
Beginner
482 pages
12h 56m
English
When run, dir will return all the corresponding values and methods, connected to the given object, as an array of strings. This is a convenient way to drill down and investigate all the methods and values of the particular variable:
>>> dir('Hello world')['__add__', '__class__', '__contains__', '__delattr__', '__dir__',... 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
We removed some lines in order to save some space in the book in the preceding code. Feel free to execute that function yourself. As you can see, the list includes all the methods we described in the previous chapter—including title, upper, and zfill, and many others besides.
Let's now take a look at ...