Python Functionality:

Interactive help - How I went from disfunctional to functional in Python.



#The first function to learn is the dir function.

>>> dir() #Short for directory.

['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']

Let's focus on '__builtins__' - a collection of common objects that are always available.
You do not have to import them to use them.
To see the list of built-in objects, we have to view the directory of the builtin's module.

>>> dir(__builtins__)

#This shows a list of dozens of functions ready to use.
-------------------------------------------------------------------------------------
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError',

'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError',

'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError',

'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError',

'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError',

'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError',

(cont.)

'exec', 'exit', 'filter', 'float', 'format', 'frozenset',

'getattr', 'globals', 'hasattr', 'hash', 'help',

'hex', 'id', 'input', 'int', 'isinstance', 'issubclass',

'iter', 'len', 'license', 'list', 'locals', 'map', 'max',

'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord',

'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed',

'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod',

'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']


#To learn about one of these objects, you call the help function with the name of the object.

Let's learn about the pow function.

>>> help('pow')

pow(x, y, z=None, /) OR pow(x, y[, z])
#A parameter enclosed in brackets [] is optional.

The following lines show how to use the function.

#There are three inputs/parameters listed - x,y and z.

x - number which is to be powered y - number which is to be powered with x z (Optional) - number which is to be used for modulus operation Equivalent to x**y (with two arguments) or x**y % z (with three arguments)

#Some types, such as ints, are able to use a more efficient algorithm when invoked using the three argument form.

Let's raise 2 to the 10th power
>>> pow(2,10)
1024
#Same answer as 2**10


Let's look at the help information on the hex function

Help on built-in function hex in module builtins: Return the hexadecimal representation of an integer.

>>> hex(12648430)
'0xc0ffee'
>>> 0xc0ffee
12648430


#It is possible to see a list of all modules available for you to use. The list available is HUGE.

>>> help('modules')
------------------------------------------------
AptUrl babel httplib2 requests

CommandNotFound base64 icu requests_unixsocket

Crypto bdb idlelib resource

IPython binascii idna rlcompleter

NvidiaDetector binhex imagesize rmagic

Onboard bisect imaplib roman

PAM bleach imghdr rope

(cont.)

_csv builtins macpath sphinx

_ctypes bz2 macurl2path spwd

ast gzip queue xxsubtype

astroid hashlib quopri yaml

asynchat heapq random youtube_dl

asyncio hmac re zipapp

asyncore hpmudext readline zipfile

atexit html redshift_gtk zipimport

audioop html5lib reportlab zlib

autoreload http reprlib zmq


#Enter any module name to get more help:

>>> help('re')
#Returns extensive information on Python Regular expressions.

>>> help('math')
#This module provides access to the mathematical functions defined by the C standard.