0% found this document useful (0 votes)
3 views9 pages

Python Interview QA 100

Uploaded by

Joni Hansome
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)
3 views9 pages

Python Interview QA 100

Uploaded by

Joni Hansome
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
You are on page 1/ 9

■ 100 Intermediate-Level Python Interview

Questions (Simple Notes)

■ Python Basics & Data Types (Q1–Q10)

1. Python dynamically typed language kyun kehlata hai?


■ Variable banate waqt type batana nahi padta, type runtime pe decide hoti hai.

2. `is` aur `==` mein kya farq hai?


■ `==` values compare karta hai, `is` memory address compare karta hai.

3. Mutable vs Immutable objects?


■ Mutable (list, dict) change hote hain, Immutable (str, tuple) change nahi hote.

4. Strings immutable kyun hote hain?


■ Security + memory optimization ke liye.

5. `id()` function kya karta hai?


■ Object ka unique memory address deta hai.

6. `None`, `False`, aur `0` mein kya difference hai?


■ None = no value, False = boolean, 0 = number.

7. Shallow copy vs Deep copy?


■ Shallow = sirf top-level copy, Deep = nested bhi copy.

8. Tuples immutable hone ke bawajood mutable objects kyun store karte hain?
■ Tuple ki structure fix hai, andar ka object mutable ho sakta hai.

9. Dict ke keys immutable kyun hone chahiye?


■ Hashing ke liye immutability zaroori hai.

10. Frozenset kya hota hai?


■ Immutable set.

---

■ Control Flow & Iteration (Q11–Q15)

11. Ternary operator kaise likhte hain?


■ `a if condition else b`

12. List comprehension vs Generator expression?


■ List eager (poori memory me), Generator lazy (ek-ek karke).

13. break, continue, pass difference?


■ break = loop end, continue = next iteration, pass = placeholder.

14. For-else / While-else?


■ Else tabhi chalega jab loop normal khatam ho (break na ho).

15. Infinite loop kaise?


■ `while True:`

---

■ Functions (Q16–Q25)

16. Default arguments kaise handle hote hain?


■ Sirf ek bar evaluate hote hain (mutable caution).

17. *args, **kwargs?


■ Extra positional (*args) tuple me, keyword (**kwargs) dict me.

18. Function annotations?


■ Type hints ke liye.

19. Higher-order function?


■ Function ko input ya output ke taur pe handle karta hai.

20. map, filter, reduce?


■ map=transform, filter=condition, reduce=combine.

21. Recursion limit check/change?


■ `sys.getrecursionlimit()` / `sys.setrecursionlimit()`

22. Lambda limitations?


■ Ek line, sirf expression.

23. zip()?
■ Multiple iterables ko pair banata hai.

24. Closures?
■ Inner function jo outer ke variables yaad rakhe.
25. lru_cache?
■ Function results ko cache karta hai.

---

■ OOP (Q26–Q35)

26. Class vs Object?


■ Class blueprint hai, Object uska instance.

27. Staticmethod, Classmethod, Instance method?


■ Instance=self, Class=cls, Static independent.

28. super()?
■ Parent class ka method call karna.

29. Multiple inheritance?


■ Ek class multiple parents se inherit.

30. MRO?
■ Method search order.

31. Private/Protected members?


■ _var protected, __var private.

32. Duck typing?


■ Behavior se type decide karna.

33. Dataclass?
■ Auto init, repr, eq generate karta hai.

34. __init__ vs __new__?


■ __new__ object banata hai, __init__ initialize karta hai.

35. Polymorphism?
■ Same function/method different behavior.

---

■ Modules & Packages (Q36–Q40)


36. Module vs Package?
■ Module=single .py file, Package=folder + __init__.py.

37. Relative vs Absolute import?


■ Absolute=full path, Relative=dot notation.

38. __init__.py role?


■ Package ko initialize karta hai.

39. Virtual environment?


■ Project-wise dependencies isolate karta hai.

40. pip freeze vs pip list?


■ freeze=for requirements.txt, list=general info.

---

■ Decorators & Generators (Q41–Q50)

41. Decorators?
■ Function ke behavior ko modify karte hain.

42. Nested functions?


■ Function ke andar function.

43. Generator vs Iterator?


■ Generator yield karta hai, Iterator class-based hota hai.

44. yield?
■ Function ko pause-resume karta hai.

45. Coroutine?
■ Generator jo value receive bhi kar sake.

46. Context manager?


■ __enter__, __exit__ define karke resources manage.

47. @property?
■ Method ko attribute ki tarah use karna.

48. Custom iterator?


■ __iter__ + __next__ define karna.

49. Async generators?


■ Async def + yield + await.

50. Chaining decorators?


■ Multiple decorators ek function pe.

---

■ Exception Handling (Q51–Q55)

51. Exception hierarchy?


■ BaseException → Exception → specific errors.

52. try-except-else-finally?
■ else tab chalega jab exception na aaye, finally hamesha.

53. Custom exception?


■ Exception inherit karke class banao.

54. raise vs assert?


■ raise=manually error, assert=debug condition check.

55. with suppress?


■ Exception ignore karne ke liye.

---

■ File Handling (Q56–Q60)

56. Text vs Binary mode?


■ Text=strings, Binary=raw bytes.

57. read(), readline(), readlines()?


■ read=all, readline=one line, readlines=list of lines.

58. seek(), tell()?


■ tell=pointer pos, seek=pointer move.

59. JSON to Python?


■ json.load()

60. CSV as dict?


■ csv.DictReader()

---

■ Python Internals (Q61–Q70)

61. GIL?
■ Ek time me ek hi thread run karta hai.

62. Bytecode?
■ Intermediate compiled code.

63. __pycache__?
■ Bytecode store karta hai.

64. CPython vs PyPy?


■ CPython default, PyPy fast (JIT).

65. Garbage collection?


■ Reference counting + cyclic collector.

66. sys.getsizeof()?
■ Object ka memory size.

67. id() vs hash()?


■ id=memory address, hash=hash value.

68. Reference counting?


■ Ref count 0 hote hi delete.

69. Interning?
■ Small immutable objects reuse.

70. weakref?
■ Weak reference without preventing GC.

---

■ Standard Library (Q71–Q80)


71. defaultdict, Counter?
■ defaultdict=default values, Counter=frequency.

72. itertools?
■ Iterator tools (count, cycle, combinations).

73. functools.partial?
■ Function ke kuch arguments fix karna.

74. datetime vs time?


■ datetime=calendar style, time=low-level.

75. shutil vs os?


■ shutil=file ops, os=system ops.

76. subprocess?
■ System commands run karna.

77. logging?
■ Program logs banane ke liye.

78. uuid?
■ Unique IDs.

79. pickle vs json?


■ pickle=Python-only, json=universal.

80. enum?
■ Fixed set of values.

---

■ Data Structures & Algorithms (Q81–Q90)

81. List vs Array?


■ List dynamic, Array fixed type.

82. Stack, Queue?


■ Stack=list, Queue=deque.

83. Priority queue?


■ heapq.

84. bisect?
■ Sorted insert/search.

85. Linked list?


■ Node class with data+next.

86. Sorted dict traversal?


■ sorted(dict.keys()).

87. Binary search?


■ bisect / manual mid index.

88. Heap?
■ heapq (min-heap).

89. Set ops?


■ union(|), intersection(&).

90. Graph representation?


■ Adjacency list (dict of lists).

---

■ Advanced Topics (Q91–Q100)

91. Multithreading vs Multiprocessing?


■ Threads=same process, Processes=parallel cores.

92. async/await?
■ Async def banata hai, await pause-resume.

93. Event loop?


■ Async tasks manage karta hai.

94. Race condition?


■ Multiple threads conflict → Locks.

95. Thread-safe data structures?


■ queue.Queue, Manager objects.

96. Memory leak detect?


■ gc, tracemalloc, objgraph.

97. Monkey patching?


■ Runtime pe modify karna.
98. Metaclass?
■ Class banane wali class.

99. Reflection?
■ getattr, setattr se runtime me attributes.

100. Unit testing?


■ unittest, pytest use karte hain.

You might also like