Header Ads

Python Interview Questions and Answers

Python Interview Questions and Answers
1. What is Python? What are benefits of using Python? 

 Python is a programming language with objects, modules, threads, exceptions and automatic memory management. The benefits of pythons are that it is simple and easy, portable, extensible, build in data structure an it is an open source. 

2. What is PEP 8? 

 PEP 8 is a coding convention a set of recommendation about how to write your python code more readable.

3. How Python is interpreted? 

 Python language is an interpreted language. Python program runs directly from the source code. It converts the source code that is written by the programmer into on intermediate language, which is again translated into machine language that has to be executed. 

4. What is pickling and unpickling?

Pickle module accepts any python object and converts it into a string representation and dumbs in into a file by using dump function, this process is called pickling. While the process of retrieving original Python objects from the stored string representation is called unpickling.

5. What are Python decorators? 

 A Python decorator is a specific change that we make in python syntax to alter function easily. 

6. What are the tools that help to find bugs or perform static analysis? 

 Pychecker is a static analysis tool that detects that bugs in python source code and warns about the style and complexity of the bug. Pylint is another tool that verifies whether the module meets the coding standard.

7. What is slicing in Python? 

 A mechanism to select a range of items from sequence types like list, tuple, strings etc., is known as slicing.

8. What is the difference between list and tuple? The difference between list and tuple is that list is mutable which tuple is not. Tuple can be hashed for e.g as a key for dictionaries. 

9. What is unit test in Python? 

 A unit testing framework in Python is known as unit test. It supports sharing of setups, automation testing, shutdown code for tests, aggregation of tests into collections etc. 

10. How are arguments passed by value by reference? 

 Everything in Python is an object and all variables hold references to the objects. The references values are according to the functions as a result you cannot change the value of the references. However you can change the objects if it is mutable. 

11. What are generators in Python?

The way of implementing iterators are known as generators. It is a normal function except that it yields expression in the function. 

12. What is docstring in Python?

A Python documentation string is known as docstring, it is a way of documenting Python functions, modules and classes. 

13. How can you copy an object in Python? 

 To copy an object in python, you can try copy.copy() or copy.deepcopy() for the general case. You cannot copy all objects but most of them.

14. What is negative index in Python? 

 Python sequences can be index in positive and negative numbers.For positive index, 0 is the first index, 1 is the second index and so forth.For negative index, (-1) is the last index and (-2) is the second last index and so forth. 

15. What is the difference between Xrange and range?

Xrange returns the Xrange object while range returns the list, and uses the same memory and no matter what the range size is. 

16. What is module and package in Python? 

 In Python, module is the way to structure program. Each Python program file is a module, Which imports other modules like objects and attributes. The folder of Python program is a package of modules. A package can have modules or subfolders.

17. How can you share global variables across modules? 

 To share global variables across modules within a single program, create a special module. Import the config module in all modules of your application. The module will be available as a global variable across modules.

18. Explain how can you access a module written in Python from C? 

You can access a module written in python from C by following method,
Module = PyImport_ImportModule("")

No comments:

Powered by Blogger.