print(dir())
Output
['In', 'Out', '_', '_2', '__', '___', '__builtin__', '__builtins__',
'__doc__', '__loader__', '__name__', '__package__', '__spec__', '_dh',
'_i', '_i1','_i2', '_i3', '_ih', '_ii', '_iii', '_oh', 'exit',
'get_ipython', 'quit']
Using a module
class my_class():
def __dir__(self):
return ['One','Two','Three']
dir(my_class())
Output
['One', 'Three', 'Two']
If __dir__() is not there then __dict__ is used. ( __dict__ is the dictionary containing the object's symbol table)
class my_class():
def my_name(self):
self.name='plus2net'
self.age=20
return self.name
my=my_class()
#print(my.my_name())
print(dir(my_class()))
#print(my.__dict__)
my_list=['One','Two','Three']
print(dir(my_list))
Output
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__',
'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
import math
print(dir(math))
Output
['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'pi', 'pow', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc']
import builtins
for i in dir(builtins):
#print("<tr><td>" + i + "</td><td> </td></tr>")
print(i)
print("Total Builtin Functions : ",len(dir(builtins)))
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.