0% found this document useful (0 votes)
4 views3 pages

Python Interview Q&A: Key Concepts Explained

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Python Interview Q&A: Key Concepts Explained

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Interview Questions and Answers

1. What are Python's key features?

Answer: Python is interpreted, high-level, dynamically typed, garbage-collected, and supports OOP,

functional, and procedural styles.

2. What is PEP 8?

Answer: PEP 8 is Python's official style guide that outlines best practices for writing clean, readable

code.

3. What are Python's data types?

Answer: Common data types include int, float, str, list, tuple, dict, set, bool, and NoneType.

4. What is the difference between list and tuple?

Answer: Lists are mutable, whereas tuples are immutable.

5. Explain Python's memory management.

Answer: It includes private heap space, garbage collection, and memory pooling.

6. What are Python decorators?

Answer: Decorators allow you to modify the behavior of a function or class without changing its

code.

7. What is a lambda function?

Answer: An anonymous function expressed using the lambda keyword, often used for short, simple

operations.

8. What is the difference between `is` and `==`?

Answer: `is` checks identity (memory location), while `==` checks value equality.

9. Explain the use of `*args` and `**kwargs`.

Answer: `*args` allows passing a variable number of positional arguments; `**kwargs` allows

passing variable keyword arguments.


10. What is a Python module and package?

Answer: A module is a single Python file, and a package is a directory with `__init__.py` containing

modules.

11. What is the difference between shallow and deep copy?

Answer: Shallow copy copies references; deep copy copies all nested objects recursively.

12. What are Python's exception handling keywords?

Answer: `try`, `except`, `else`, `finally`, and `raise`.

13. How is memory managed in Python?

Answer: Through reference counting and cyclic garbage collector.

14. What is the Global Interpreter Lock (GIL)?

Answer: A mutex that allows only one thread to execute at a time in CPython, affecting

multi-threading performance.

15. Explain list comprehension.

Answer: A concise way to create lists using a single line of code, e.g., [x for x in range(10) if

x%2==0].

16. What is the difference between Python 2 and 3?

Answer: Python 3 introduced many breaking changes like print() function, integer division, unicode

strings by default, etc.

17. How do you manage packages in Python?

Answer: Using pip, the package installer for Python.

18. What is the use of `with` statement?

Answer: Used for resource management and exception handling (e.g., opening files).

19. Explain the difference between `del`, `remove()`, and `pop()`.

Answer: `del` deletes by index or entire list; `remove()` removes first matching value; `pop()`

removes by index and returns item.


20. What is the difference between compile-time and run-time errors?

Answer: Compile-time errors occur during code compilation (syntax); run-time errors occur during

execution (e.g., ZeroDivisionError).

You might also like