The dir
built-in function in Python allows one to explore the contents of an object.
That is, the dir
function returns a list
of an object's attributes, which can be either data (i.e., variables) or functions.
Don't believe me? Try out the dir
function on anything you can think of...
dir('string')
Some attributes have names that start with __ (double-underscore). In Python, variables or functions that start with a double-underscore are treated as "private." In general, variables or functions that start with a double-underscore and end with a double-underscore typically have special meaning. We'll get to that later.
dir(1)
# What attributes does a list have?
# What attributes does a dict have?
# What attributes does a function have?
Do you recognize any of the attributes listed above?
Jupyter Notebooks have the wonderful ability to show you an object's attributes just by adding a "dot" and then hitting tab. Jupyter's built-in tab completion capability will then pop up a window to show you the attributes of the object!
i = 2
i.
Jupyter's visual "pop-up" shows an object's public attributes only. If you are using JupyterLab, you will see that each attribute is labeled as either an instance (i.e., data) or a function. If you are using classic Jupyter Notebooks, then you will just see a list of the attributes (without additional labeling).
Jupyter can't give you a pop-up window unless the variable you are using to tab-complete is already defined and created!