Python Interview Questions Part 2
Python Modules and Packages
What is a module in Python?
Describe the differences between
import
andfrom...import
statements in Python.How do you install and use third-party libraries in Python?
Explain the purpose of a virtual environment in Python development.
Describe the use of built-in modules like
os
,sys
, anddatetime
in Python.
File Handling and Input/Output
How do you open and close a file in Python?
Explain the differences between reading and writing modes for files in Python.
Describe the use of context managers (
with
statement) in Python file handling.How do you handle file exceptions in Python?
Explain the purpose of pickling and unpickling in Python.
Python Decorators and Generators
What is a decorator and how is it used in Python?
Describe the purpose of the
@property
decorator in Python.Explain the concept of a generator in Python.
How does the
yield
keyword work in Python generators?
Advanced Python Concepts
Explain the Global Interpreter Lock (GIL) in Python.
What are metaclasses in Python and how are they used?
Describe the purpose of the
__slots__
attribute in Python.How does Python manage memory for large data structures?
Explain the use of the
asyncio
module in Python for asynchronous programming.What is monkey patching in Python and when is it used?
Describe the purpose of the
collections
module in Python.Explain the differences between Python's
range()
andxrange()
functions (Python 2).