Q71. How would you find the current module name?

Ans : You can use __name__ to find the name of current module. But if it is run by script than , __name__ will be  equal to “__main__ ”

 

Q72. What is the difference between dir and help function?

Ans : Both the function will help you get the detail about modules. There usage are below.

  • If you write only dir, without any () braces , it will return all the names in current scope.

 

Using dir() function for each of the below behaves like

 

  • For module: It will return all the module’s attributes and functions.
  • For Class object: It will return all the attributes of the same class as well as the base class attributes.

 

-          dir()

Returns the attributes of the object or module.

-          help()

Returns the python built in documentation about the object.

-          type()

Returns the type of object.

-          __doc__

Returns the doc-string of object or module.

 

help() : Help function, name itself defines the usage of this function. This function returns the help related to python module, object or method if it is called with respective argument but without any argument it will return the help related to currently running programming module.  

 

Q73. Can we override the dir() function behavior?

Ans: Yes, you can. By overriding __dir__ function.

 

Q74. How would you get builtin function using dir()

Ans: You can get all the builtin functions using dir(__builtins__)

 

Q75. Why Python does not de-allocate all the memory on exits?

Ans: Python does not de-allocate all the memory as soon as it exits, because some memory is reserved by C library and possible there could be some circular references exists. Hence, memory can not be de-allocated immediately in Python.

Why Dont you prepare for Python Certifications and Interview Questions with 250+ Questions and Answer : Check Here

Real Exam Number of Questions: 70 Questions
Real Exam Pass Score: 70%
Time Allotted: 90 minutes to complete exam