BSE 224 - python programming QB
BSE 224 - python programming QB
Compulsory Questions
3. What are Python's magic methods and provide three examples with their uses?
(5 marks)
4. How would you implement a custom iterator in Python? Provide code examples.
(10 marks)
7. How does Python's with statement work and what protocol does it use? (5
marks)
10. What are Python's context managers and how would you implement one? (5
marks)
13. How does Python's *args and **kwargs work? Provide examples. (5 marks)
14. What are decorators in Python and how would you create one? (10 marks)
15. Explain the difference between map(), filter(), and reduce() functions. (5 marks)
17. What are generator functions and how do they differ from normal functions? (5
marks)
20. What are Python's function annotations and how are they used? (5 marks)
Object-Oriented Programming
21. Explain Python's method resolution order (MRO) with examples. (5 marks)
22. How does multiple inheritance work in Python and what are its pitfalls? (5 marks)
23. What are abstract base classes and how would you implement them? (5 marks)
26. What are Python's property decorators and when would you use them? (5 marks)
27. Explain the difference between composition and inheritance in Python. (5 marks)
28. How would you implement the singleton pattern in Python? (5 marks)
29. What are Python's descriptors and how do they work? (5 marks)
Exception Handling
31. What is the difference between SyntaxError, Exception, and RuntimeError? (5
marks)
35. How would you implement retry logic for a failed operation? (5 marks)
36. What is the assert statement used for and when would you use it? (5 marks)
37. Explain how to properly handle resources with exceptions in Python. (5 marks)
38. What are contextlib utilities and how do they help with exception handling? (5
marks)
40. What is the difference between raise Exception and raise Exception from cause?
(5 marks)
42. Explain the difference between text mode and binary mode when opening files.
(5 marks)
44. What are Python's StringIO and BytesIO classes used for? (5 marks)
45. How would you handle CSV files with different encodings? (5 marks)
47. What are Python's tempfile utilities and when would you use them? (5 marks)
48. How would you implement a simple file watcher in Python? (5 marks)
49. Explain how to handle file paths portably across different operating systems. (5
marks)
50. What are the best practices for working with file permissions in Python? (5
marks)
54. What are Python's coroutines and how do they differ from threads? (5 marks)
55. Explain how asyncio works in Python with examples. (5 marks)
56. How would you handle shared state between threads safely? (5 marks)
57. What are Python's futures and how are they used? (5 marks)
59. How would you implement parallel processing for CPU-bound tasks? (5 marks)
60. What are the common pitfalls when working with threads in Python? (5 marks)
62. Explain how to make HTTP requests using the requests library. (5 marks)
63. What are WebSockets and how would you implement them in Python? (5 marks)
64. How would you scrape a website while respecting robots.txt? (5 marks)
66. What are Python's urllib and urllib2 libraries used for? (5 marks)
67. How would you implement a simple chat server in Python? (5 marks)
68. Explain how to handle cookies and sessions in Python web requests. (5 marks)
69. What are Python's async HTTP clients and when would you use them? (5 marks)
70. How would you implement rate limiting for API requests? (5 marks)
72. Explain the difference between NumPy arrays and Python lists. (5 marks)
73. What are pandas DataFrames and how are they used? (5 marks)
76. What are the advantages of using NumPy over native Python for numerical
computations? (5 marks)
80. How would you optimize memory usage when working with large DataFrames? (5
marks)
84. What are Python's debugging tools and how would you use them? (5 marks)
85. How would you profile a Python application to find performance bottlenecks? (5
marks)
88. How would you implement continuous integration for a Python project? (5
marks)
92. Explain Python's virtual environments and why they are important. (5 marks)
93. What are the differences between pip, conda, and poetry? (5 marks)
94. How would you deploy a Python web application in production? (5 marks)
96. What are Python wheels and why are they beneficial? (5 marks)
99. What are the best practices for Python project structure? (5 marks)
o Shallow copy creates a new object but doesn't create copies of nested
objects, just references them.
o Deepcopy creates a new object and recursively copies all objects found
in the original.
3. Magic Methods:
4. Custom Iterator:
5. __name__ variable:
o Contains the name of the current module
6. @staticmethod vs @classmethod:
7. with statement:
8. __str__ vs __repr__:
9. Immutable Class: