Python - Q & A

Python 100 Interview Questions & Answers

Python 100 Interview-Only Questions & Answers

Core Python Concepts

Q1. Is Python interpreted or compiled?

Python is interpreted but internally compiled to bytecode.

Q2. What is Python bytecode?

Intermediate code (.pyc) executed by Python Virtual Machine.

Q3. What is PVM?

Python Virtual Machine executes bytecode.

Q4. What is dynamic typing?

Variable type is decided at runtime.

Q5. Mutable vs Immutable?

Mutable: list, dict | Immutable: int, str, tuple

Q6. Why Python is slow?

Because it is interpreted and dynamically typed.

Q7. What is memory management in Python?

Automatic via garbage collector.

Q8. What is reference counting?

Tracks number of references to an object.

Q9. What is garbage collection?

Frees unused memory automatically.

Q10. What is GIL?

Global Interpreter Lock allows one thread at a time.

Q11. Why GIL exists?

To manage memory safely in CPython.

Q12. Is Python thread-safe?

No, due to GIL.

Q13. Shallow copy vs Deep copy?

Shallow copies references, Deep copies objects.

Q14. What is None?

Represents absence of value.

Q15. pass vs continue?

pass does nothing, continue skips loop iteration.

Q16. break vs return?

break exits loop, return exits function.

Q17. What is __name__ == "__main__"?

Checks if script is run directly.

Q18. Python namespaces?

Local, Global, Built-in.

Q19. What is scope?

Region where variable is accessible.

Q20. LEGB rule?

Local → Enclosed → Global → Built-in

Q21. What is id()?

Returns memory address of object.

Q22. What is type()?

Returns data type.

Q23. What is del?

Deletes object reference.

Q24. What is slicing?

Extracting sequence part.

Q25. Python keywords count?

35 keywords (may vary by version).

OOPs in Python

Q26. What is OOP?

Programming using objects and classes.

Q27. Class vs Object?

Class is blueprint, object is instance.

Q28. What is __init__?

Constructor method.

Q29. self keyword?

Refers to current object.

Q30. Types of inheritance?

Single, Multiple, Multilevel, Hybrid

Q31. Method overriding?

Child redefining parent method.

Q32. Method overloading?

Not directly supported.

Q33. Polymorphism?

One interface, multiple behaviors.

Q34. Encapsulation?

Data hiding using access control.

Q35. Abstraction?

Hiding implementation details.

Q36. Abstract class?

Class with abstract methods.

Q37. Multiple inheritance issue?

Diamond problem.

Q38. MRO?

Method Resolution Order.

Q39. __str__ vs __repr__?

User-friendly vs developer representation.

Q40. Static method?

Method without self.

Q41. Class method?

Uses cls instead of self.

Q42. Private variables?

Prefixed with __

Q43. Operator overloading?

Using magic methods.

Q44. __len__ method?

Returns object length.

Q45. __eq__?

Equality comparison.

Q46. Data class?

Auto-generated class for data storage.

Q47. Composition vs Inheritance?

Has-a vs Is-a relationship.

Q48. Why prefer composition?

More flexible and reusable.

Q49. What is super()?

Calls parent method.

Q50. Duck typing?

Behavior matters, not type.

Advanced & Real Interview Questions

Q51. What is decorator?

Function modifying another function.

Q52. Use of decorators?

Logging, authentication, caching.

Q53. Generator vs Function?

Generators use yield.

Q54. Iterator protocol?

__iter__ and __next__

Q55. What is yield?

Returns value and pauses function.

Q56. What is coroutine?

Function that can pause and resume.

Q57. Async vs threading?

Async is non-blocking, threading is parallel.

Q58. async/await?

Used for asynchronous programming.

Q59. What is multiprocessing?

Uses multiple CPU cores.

Q60. When to use multiprocessing?

CPU-bound tasks.

Q61. What is pickling?

Object serialization.

Q62. JSON vs Pickle?

JSON is text-based, Pickle is binary.

Q63. What is logging?

Recording program events.

Q64. Exception vs Error?

Exceptions can be handled.

Q65. raise keyword?

Raises exception manually.

Q66. finally block?

Always executes.

Q67. What is context manager?

Manages resources using with.

Q68. __enter__ and __exit__?

Context manager methods.

Q69. What is ORM?

Object Relational Mapping.

Q70. SQLAlchemy?

Python ORM library.

Q71. Flask vs Django?

Micro vs Full-stack framework.

Q72. REST API?

Architectural style for web services.

Q73. GET vs POST?

Fetch vs send data.

Q74. Unit testing?

Testing individual components.

Q75. pytest vs unittest?

pytest is simpler.

Q76. Mocking?

Simulating objects.

Q77. CI/CD?

Continuous integration/deployment.

Q78. Virtualenv?

Isolated Python environment.

Q79. requirements.txt?

Dependency list.

Q80. pip freeze?

Lists installed packages.

Q81. Memory leak?

Unused memory not released.

Q82. Python use in AI?

Extensive libraries.

Q83. NumPy use?

Numerical computation.

Q84. Pandas use?

Data analysis.

Q85. What is TensorFlow?

ML framework.

Q86. What is PyTorch?

Deep learning framework.

Q87. Why Python for ML?

Easy and powerful libraries.

Q88. What is time complexity?

Algorithm efficiency.

Q89. Big-O?

Performance measurement.

Q90. List vs Set?

Set removes duplicates.

Q91. Python advantages?

Readable, scalable, huge ecosystem.

Q92. Python disadvantages?

Slow execution.

Q93. Python future?

Very strong.

Q94. Best Python practices?

PEP8, modular code.

Q95. Code optimization?

Use efficient algorithms.

Q96. Memory optimization?

Generators, garbage collection.

Q97. Python for backend?

Yes, widely used.

Q98. Python for automation?

Excellent choice.

Q99. Python interview focus?

Concepts + problem solving.

Q100. Why hire Python developer?

Versatile, productive, scalable.

No comments:

Post a Comment