1.

What is the use of dir () function in Python?

Answer»

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.

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']



Discussion

No Comment Found