Python Interview Questions and Answers
Python Interview Questions and Answers
Python Interview Questions and Answers
Ans: 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 and it is an open
source.
2. What is PEP 8?
Ans: PEP 8 is a coding convention, a set of recommendation, about how to write your Python code more readable.
3. What is pickling and unpickling?
Ans: The process of writing state of object to the file by using dump function is called pickling and the process of
reading state of an object from the file is called unpickling.
4. How Python is interpreted?
Ans: PVM reads Line by Line of Byte Code and converted into Machine Understandable Code(Binary Code) and It is
read By OS and Processer and Gives Result.
5. How memory is managed in Python?
Ans: Python memory is managed by Python private heap space. All Python objects and data structures are located in
a private heap. The programmer does not have an access to this private heap and interpreter takes care of this
Python private heap. The allocation of Python heap space for Python objects is done by Python memory manager.
Python also have an inbuilt garbage collector makes it available to the heap space.
6. What are the tools that help to find bugs or perform static analysis?
Ans: PyChecker is a static analysis tool that detects the 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 are Python decorators?
Ans: A Python decorator is a specific change that we make in Python syntax to alter functions easily.
8. What is the difference between list and tuple?
Ans: The difference between list and tuple is that list is mutable while tuple is not. Tuple can be hashed for e.g as a
key for dictionaries.
9. How are arguments passed by value or by reference?
Ans: 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.
10. What is Dict and List comprehensions are?
Ans: They are syntax constructions to ease the creation of a Dictionary or List based on existing iterable.
11. What are the built in type does python provides?
Ans: There are mutable and Immutable types of Pythons built in types Mutable built-in types
List Sets
Dictionaries Immutable built-in types
Strings Tuples Numbers
12. What is namespace in Python?
Ans: A collection of currently defined symbolic names along with information about the object that each name
reference
13. What is lambda in Python?
Ans: It is a single expression anonymous function often used as In-line function.
14. Why lambda forms in python does not have statements?
Ans: A lambda form in python does not have statements as it is used to make new function object and then return
them at runtime.
15. What is pass in Python?
Ans: Pass means, no-operation Python statement, or in other words it is a place holder in compound statement,
where there should be a blank left and nothing has to be written there.
16. In Python what are iterators?
Ans: In Python, iterators are used to iterate a group of elements, containers like list.
17. What is unit test in Python?
Ans: 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.