Q1. What is Python? Why is it called an interpreted language?
Ans: Python is a high-level, interpreted language executed line by line by the interpreter.
Q2. Who developed Python, and when was it first released?
Ans: Guido van Rossum, 1991.
Q3. What are Python’s key features?
Ans: Simple, open-source, portable, object-oriented, extensive libraries, dynamically typed.
Q4. What are Python’s advantages and disadvantages?
Ans: Advantages: easy, rich libraries. Disadvantages: slower than compiled languages, GIL limits
threading.
Q5. What are Python’s data types?
Ans: int, float, str, bool, list, tuple, set, dict, complex, bytes, etc.
Q6. Difference between list, tuple, set, and dictionary?
Ans: List: ordered, mutable. Tuple: ordered, immutable. Set: unordered, unique elements. Dict:
key-value pairs.
Q7. Difference between mutable and immutable objects?
Ans: Mutable: can change (list, dict, set). Immutable: cannot change (tuple, str, int).
Q8. What is PEP 8?
Ans: Python Enhancement Proposal 8, style guide for Python code.
Q9. What are Python’s built-in data structures?
Ans: List, tuple, set, dictionary.
Q10. Explain indentation in Python.
Ans: Indentation defines code blocks instead of braces.
Q11. How are variables declared in Python?
Ans: By assignment, e.g., x=5.
Q12. What are naming conventions for variables?
Ans: Lowercase with underscores, avoid reserved words.
Q13. What are Python’s numeric types?
Ans: int, float, complex.
Q14. What is typecasting?
Ans: Converting one type to another using functions like int(), str().
Q15. Difference between is and == operator?
Ans: is checks identity, == checks value.
Q16. Difference between shallow and deep copy?
Ans: Shallow copy copies references, deep copy copies objects recursively.
Q17. How does Python manage memory?
Ans: Through private heap and garbage collection.
Q18. What is garbage collection?
Ans: Automatic memory management for unused objects.
Q19. Explain id() function.
Ans: Returns memory address (identity) of object.
Q20. Explain type() function.
Ans: Returns type of object.
Q21. Types of operators?
Ans: Arithmetic, comparison, logical, bitwise, assignment, membership, identity.
Q22. Difference between / and //?
Ans: / gives float division, // gives floor division.
Q23. How does ** operator work?
Ans: Exponentiation (power).
Q24. What is operator precedence?
Ans: Order in which operators are evaluated.
Q25. What are bitwise operators?
Ans: Operators on binary values: &, |, ^, ~, <<, >>.
Q26. How are strings represented?
Ans: As immutable sequences of characters.
Q27. Explain string slicing.
Ans: s[1:4] extracts substring from index 1 to 3.
Q28. Difference between isalpha(), isdigit(), isalnum()?
Ans: Checks letters, digits, letters+digits.
Q29. How to reverse a string?
Ans: Using slicing s[::-1].
Q30. What are f-strings?
Ans: Formatted string literals with f"...{var}...".
Q31. Explain if-elif-else.
Ans: Conditional branching.
Q32. Difference between for and while loop?
Ans: for iterates over sequence, while runs until condition false.
Q33. Difference between break, continue, pass?
Ans: break exits loop, continue skips iteration, pass does nothing.
Q34. What are ternary operators?
Ans: Short if-else expression: x if cond else y.
Q35. Explain list comprehension.
Ans: Compact syntax for building lists.
Q36. How to define a function?
Ans: Using def keyword.
Q37. What are default arguments?
Ans: Function parameters with default values.
Q38. Difference positional vs keyword arguments?
Ans: Positional depend on order, keyword specify names.
Q39. What are *args and **kwargs?
Ans: Variable number of arguments, * for tuple, ** for dict.
Q40. What is recursion?
Ans: Function calling itself.
Q41. Difference return vs yield?
Ans: return ends function, yield returns generator values.
Q42. What are lambda functions?
Ans: Anonymous one-line functions.
Q43. What is function overloading?
Ans: Python doesn’t support true overloading; can use default args.
Q44. What is a closure?
Ans: Function with access to variables of enclosing scope.
Q45. What are higher-order functions?
Ans: Functions that take/return other functions.
Q46. Difference between module and package?
Ans: Module is a file, package is a collection of modules.
Q47. How to import module?
Ans: Using import statement.
Q48. Role of __init__.py?
Ans: Marks directory as package.
Q49. What is Python’s standard library?
Ans: Collection of built-in modules.
Q50. How to install packages?
Ans: Using pip install.
Q51. What are classes and objects?
Ans: Class defines blueprint, object is instance.
Q52. Difference class vs instance variables?
Ans: Class shared, instance specific.
Q53. Explain inheritance.
Ans: Child class acquires parent class features.
Q54. What is multiple inheritance?
Ans: Class inherits from multiple parents.
Q55. What is method overriding?
Ans: Subclass redefines parent method.
Q56. What are decorators?
Ans: Functions that modify other functions.
Q57. Difference staticmethod, classmethod, instance method?
Ans: staticmethod no self, classmethod uses cls, instance uses self.
Q58. What is polymorphism?
Ans: Same method name behaves differently.
Q59. What is encapsulation?
Ans: Restrict access to data (private attributes).
Q60. What are magic methods?
Ans: Special methods with __ like __init__, __str__.
Q61. What are exceptions?
Ans: Runtime errors handled by try/except.
Q62. Difference syntax error vs exception?
Ans: Syntax error before execution, exception during execution.
Q63. How to handle exceptions?
Ans: Using try-except-finally.
Q64. Difference try-except-finally vs try-except-else?
Ans: Else runs if no exception, finally always runs.
Q65. What are custom exceptions?
Ans: User-defined exception classes.
Q66. How to open file?
Ans: open('[Link]', 'r').
Q67. Difference read(), readline(), readlines()?
Ans: Reads all, one line, list of lines.
Q68. How to write file?
Ans: Using write() or writelines().
Q69. Difference text vs binary files?
Ans: Text stores characters, binary stores raw bytes.
Q70. What is with statement?
Ans: Ensures file closes automatically.
Q71. What are iterators?
Ans: Objects with __iter__ and __next__ methods.
Q72. What are generators?
Ans: Functions with yield that return iterator.
Q73. Difference iter() vs next()?
Ans: iter() gets iterator, next() gets next element.
Q74. What are coroutines?
Ans: Special functions that can pause/resume with yield.
Q75. What is GIL?
Ans: Global Interpreter Lock allows one thread execution at a time.
Q76. Multiprocessing vs multithreading?
Ans: Multiprocessing uses multiple processes, multithreading shares memory.
Q77. What is monkey patching?
Ans: Dynamic modification of classes/modules at runtime.
Q78. What is memoization?
Ans: Caching results of function calls.
Q79. What are metaclasses?
Ans: Classes of classes, control class creation.
Q80. What are descriptors?
Ans: Objects defining __get__, __set__, __delete__ for attributes.
Q81. Difference NumPy arrays vs lists?
Ans: Arrays are faster, fixed type; lists are flexible.
Q82. What is Pandas DataFrame?
Ans: 2D labeled data structure.
Q83. Explain loc[] vs iloc[].
Ans: loc label-based, iloc index-based.
Q84. How does Matplotlib work?
Ans: Library for plotting graphs.
Q85. What is TensorFlow?
Ans: Deep learning library.
Q86. Explain Flask vs Django.
Ans: Flask lightweight, Django full-featured.
Q87. What is FastAPI?
Ans: High-performance web framework for APIs.
Q88. How does Requests work?
Ans: Library for HTTP requests.
Q89. What is BeautifulSoup?
Ans: Web scraping library.
Q90. What is SQLAlchemy?
Ans: ORM for database management.
Q91. How to implement stack?
Ans: Using list with append() and pop().
Q92. How to implement queue?
Ans: Using [Link] or list pop(0).
Q93. How to implement linked list?
Ans: Using custom Node class.
Q94. Difference sort() vs sorted()?
Ans: sort modifies list, sorted returns new list.
Q95. How to implement binary search?
Ans: Divide and conquer on sorted array.
Q96. How to find duplicates in list?
Ans: Using set or Counter.
Q97. How to find factorial recursively?
Ans: Function calls itself until base case.
Q98. How to reverse linked list?
Ans: Iteratively or recursively swapping links.
Q99. How to detect cycles in graph?
Ans: Using DFS with visited set or Floyd’s cycle detection.
Q100. How to implement BFS?
Ans: Using queue to explore neighbors level by level.