In Python, the dir() function is used to return all the properties and methods within a specified object, without actually having the values. The dir() function shall return all the features and methods present, including the in-built properties, which are set as default for all the objects within.

BY Best Interview Question ON 10 Jul 2020

Example

Here’s a short example to demonstrate the dir() function in Python:

class Person:
  name = "John"
  age = 36
  country = "Norway"

print(dir(Person))

Output

['__doc__', '__module__', 'age', 'country', 'name']