/    /  Python – Interview Questions Part 1

1. Name few Python modules for Statistical, Numerical and scientific computations ?

Answer: There are few python modules for statistical, numerical and scientific computations are as follows,

1. NumPy module provides an array/matrix type, and it is useful for doing computations on arrays. 

2. scipy module provides methods for doing numeric integrals, solving differential equations, etc pylab – is a  module for generating and saving plots.

 

2. Is Python object oriented? what is object oriented programming?

Answer: Yes, Python is Object Oriented Programming language. It is the programming paradigm based on classes and instances of those classes called objects. The features of OOP are; Encapsulation, Data Abstraction, Inheritance, Polymorphism.

 

3. What is PYTHONPATH?

Answer:It is an environment variable which is used when a module is imported. Whenever a module is imported, PYTHONPATH is also looked  up to check for the presence of the imported modules in various directories. The interpreter uses it to determine which module to load.

 

4. What is namespace in Python?

Answer: A namespace is a naming system used to make sure that names are unique to avoid naming conflicts.

 

5. Is python case sensitive?

Answer: Yes. Python is a case sensitive language.

 

6. What is type conversion in Python?

Answer: Type conversion refers to the conversion of one data type iinto another.

int() – converts any data type into integer type

float() – converts any data type into float type

ord() – converts characters into integer

hex() – converts integers to hexadecimal

oct() – converts integer to octal

tuple() – This function is used to convert to a tuple.

set() – This function returns the type after converting to set.

list() – This function is used to convert any data type to a list type.

dict() – This function is used to convert a tuple of order (key,value) into a dictionary.

str() – This functionUsed to convert integer into a string.

complex(real,imag) – This functionconverts real numbers to complex(real,imag) number.

 

7. What is the difference between Python Arrays and lists?

Answer: Arrays and lists, in Python, have the same way of storing data. But, arrays can hold only a single data type elements whereas lists can hold any data type elements.

Example:

1

2

3

4

5

import array as arr

My_Array=arr.array(‘i’,[4,5,6,7])

My_list=[1,’xyz’,1.40]

print(My_Array)

print(My_list)

Output:

array(‘i’, [4, 5, 6, 7]) [1, ‘xyz, 1.4]

 

8. How to comment multiple lines in python?

Answer: Multi-line comments appear in more than one line.

  1. All the lines to be commented are to be prefixed by a #.
  2. In simple you can also the shortcut method i.e. All you need to do is hold the ctrl key and left clickin every place wherever you want to include a # character and type a # just once. This will comment all the lines where you introduced your cursor.

 

9. How are classes created in Python? 

Answer: Class in Python is created using the class keyword.

Example:

1

2

3

4

5

class Employee:

def __init__(self, name):

self.name = name

E1=Employee(“xyz”)

print(E1.name)

Output: xyz

 

10. What is scheduling?

Answer: Among multiple threads which thread as to start the execution first, how much time the thread as to execute after allocated time is over, which thread, as to continue the execution next this, comes under scheduling. Scheduling is highly dynamic

 

11. How do you do data abstraction in Python?

Answer: Data Abstraction is providing only the required details and hiding the implementation from the world. It can be achieved in Python by using interfaces and abstract classes.

 

12. Define encapsulation in Python?

Answer: Encapsulation means binding the code and the data together. A Python class in an example of encapsulation.

 

13. Does python make use of access specifiers?

Answer: Python does not deprive access to an instance variable or function. Python lays down the concept of prefixing the name of the variable, function or method with a single or double underscore to imitate the behavior of protected and private access specifiers.

 

14. How to create an empty class in Python? 

Answer: An empty class is a class that does not have any code defined within its block. It can be created using the pass keyword. However, you can create objects of this class outside the class itself. When a Pass command is executed it show a null statement.

For example-

1

2

3

4

5

class a:

pass

obj=a()

obj.name=”xyz”

print(“Name = “,obj.name)

Output: 

Name =  xyz

 

15. What is the difference between .py and .pyc files ?

Answer:.py files are Python source files. .pyc files are the compiled bvtecode files that is generated by the Python compiler.