Printing all the global methods in Python REPL
Question: In Python REPL

    
    
    dir(str)
    

prints

    
    
    ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__',   '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
    

i.e.. all the available methods for string.

How can I view all the global methods available like "print", "list" , "len"
etc. ?


Answer: 
    >>> dir(__builtins__)
    ['ArithmeticError', 'AssertionError', 'AttributeError',
     ...  # a whole bunch of other Errors
     'abs', 'all', 'any',
     ...  # other builtins
     'type', 'vars', 'zip']
    

As @eryksun mentioned in his comment, this will only work in the `__main__`
module. If you want to do this in an imported module, use
`sorted(__builtins__)`.

