Python Interview Questions

Learn Python in Less than 8 Hrs Sitting @ Home /Desk with HandsOn

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.

Q76. What zip() function does?

Ans : zip() function will combine multiple lists elements based on their position and create tuple out of this. See below example

l3=['hadoop' , 'exam' , 'learning']
[(1, 'a', 'hadoop'), (2, 'b', 'exam'), (3, 'c', 'learning')]

It will create tuple only the minimum length of the any list.

Q77. What is the Pass by Value and Pass by Reference?

Ans : Whenever arguments passed to the function they are always passed by reference. It means, if you change the value of the function inside the parameter, it will also change the value of the original parameter. However, if you are passing immutable variable then it will be pass by value, hence original copy of the variable will not be changed.

Q78. Is everything object in Python?

Ans : Everything in Python is an object, and almost everything has attributes and methods. All functions have a built-in attribute __doc__, which returns the doc string defined in the function's source code. The sys module is an object which has (among other things) an attribute called path.

Q79. What is an id() function?

Ans : id() unction provide the unique integer value of an object.

Q80. What is the purpose of the __init__ method?

Ans : The __init__ method is run as soon as an object of a class is instantiated. The method is useful to do any initialization you want to do with your object.

Learn Python in Less than 8 Hrs Sitting @ Home /Desk with HandsOn

Premium Training : Spark Full Length Training : with Hands On Lab

Previous Next

Home Spark Hadoop NiFi Java

Disclaimer :

1. Hortonworks® is a registered trademark of Hortonworks.

2. Cloudera® is a registered trademark of Cloudera Inc

3. Azure® is aregistered trademark of Microsoft Inc.

4. Oracle®, Java® are registered trademark of Oracle Inc

5. SAS® is a registered trademark of SAS Inc

6. IBM® is a registered trademark of IBM Inc

7. DataStax ® is a registered trademark of DataStax

8. MapR® is a registered trademark of MapR Inc.

2014-2017 © | Dont Copy , it's bad Karma |