RI Study Post Blog Editor

Python Interview Questions

 

Basic Python Interview Questions - Complete Guide

Fundamentals & Syntax

  1. What is Python and why is it popular?
  2. What are the differences between Python 2 and Python 3?
  3. What is PEP 8 and why is it important?
  4. Explain mutable vs immutable data types in Python with examples.
  5. What is the difference between == and is?
  6. How do you comment in Python?
  7. What are Python's naming conventions?
  8. Explain the concept of indentation in Python.
  9. What is the GIL (Global Interpreter Lock)?
  10. How does Python handle memory allocation?

Data Types & Variables

  1. What are the main data types in Python?
  2. How do you check the type of a variable?
  3. What is type casting and how do you do it?
  4. Explain the difference between lists, tuples, and sets.
  5. What are dictionaries and how do you access elements?
  6. Can you have duplicate values in a set?
  7. What is the difference between append() and extend() on lists?
  8. How do you create an empty list, dictionary, and set?
  9. Explain string slicing with examples.
  10. What are f-strings and how do you use them?
  11. What is a frozenset?
  12. How do you check if a key exists in a dictionary?
  13. What is the difference between dict.get() and dict[]?
  14. How do you sort a dictionary by keys or values?
  15. What are bytes and bytearray in Python?

Operators & Control Flow

  1. What are the different types of operators in Python?
  2. Explain the difference between / and // operators.
  3. What are comparison operators and provide examples.
  4. What is short-circuit evaluation in Python?
  5. Explain if, elif, and else statements with an example.
  6. What is the ternary operator in Python?
  7. What is the purpose of pass statement?
  8. Explain break and continue statements.
  9. What is the in operator?
  10. What is the not in operator?
  11. How does operator precedence work in Python?
  12. What is the and, or, and not operators?

Loops & Iteration

  1. What are the different types of loops in Python?
  2. Explain for and while loops with examples.
  3. What is the difference between a for and while loop?
  4. How do you use enumerate() in a loop?
  5. What is a list comprehension and provide an example?
  6. What is a dictionary comprehension?
  7. What is a set comprehension?
  8. What is a generator expression?
  9. How do you iterate through a dictionary?
  10. What is the else clause in loops?
  11. How do you create an infinite loop and how do you exit it?
  12. What is the difference between range() and xrange()?

Functions

  1. What is a function and why are they useful?
  2. What is the difference between parameters and arguments?
  3. What are default arguments in a function?
  4. What are keyword arguments?
  5. Explain *args and **kwargs.
  6. What is the difference between return and print()?
  7. What is a lambda function and when should you use it?
  8. What are higher-order functions?
  9. Explain the map(), filter(), and reduce() functions.
  10. What is the scope of variables in Python (LEGB rule)?
  11. What is the global keyword used for?
  12. What is the nonlocal keyword used for?
  13. How do type hints work in Python?
  14. What is a generator function?
  15. What is the yield keyword?
  16. What is the difference between a generator and a list?
  17. How do you use next() with generators?
  18. What are *args order and **kwargs order in function parameters?

Object-Oriented Programming

  1. What is a class and an object?
  2. What is the difference between a class variable and instance variable?
  3. What is self in Python classes?
  4. What is the __init__ method?
  5. What are special methods (dunder methods) in Python?
  6. Explain inheritance in Python.
  7. What is method overriding?
  8. What is method overloading in Python?
  9. Explain polymorphism in Python.
  10. What is encapsulation in Python?
  11. What are properties and how do you create them?
  12. What is the super() function?
  13. What is the difference between composition and inheritance?
  14. What are abstract classes and abstract methods?
  15. What are class methods and static methods?
  16. What is multiple inheritance?
  17. What is the Method Resolution Order (MRO)?
  18. What is the __str__ and __repr__ method?
  19. What is the __eq__ method?
  20. What is the __hash__ method?
  21. What is the __call__ method?
  22. What are descriptors in Python?
  23. What is a metaclass?
  24. How do private variables work in Python?
  25. What are name mangling?
  26. What is the @property decorator?
  27. How do you create a singleton class?

Exceptions & Error Handling

  1. What is an exception in Python?
  2. What is the difference between syntax errors and exceptions?
  3. How do you handle exceptions using try-except?
  4. What is the difference between except and finally?
  5. Can you have multiple except blocks?
  6. How do you raise an exception?
  7. What is a custom exception?
  8. What is the else clause in try-except?
  9. What is the with statement used for?
  10. What are common built-in exceptions?
  11. What is exception chaining?
  12. How do you access exception information?
  13. What is the difference between raise and raise from?

File Handling

  1. How do you open and read a file in Python?
  2. What are the different file opening modes?
  3. How do you write to a file?
  4. What is the difference between read(), readline(), and readlines()?
  5. How do you close a file safely?
  6. What is the context manager (with statement) for files?
  7. How do you append to a file?
  8. How do you delete a file?
  9. How do you check if a file exists?
  10. How do you get file size?
  11. How do you work with file paths in Python?
  12. What is the difference between absolute and relative paths?
  13. How do you read/write binary files?

String Operations

  1. How do you concatenate strings in Python?
  2. What are string methods like upper(), lower(), strip()?
  3. How do you check if a substring exists in a string?
  4. How do you split and join strings?
  5. What is string formatting and what are the different methods?
  6. How do you replace characters in a string?
  7. What are escape sequences in Python?
  8. How do you find the length of a string?
  9. What is the startswith() and endswith() method?
  10. How do you reverse a string?
  11. What is string interpolation?
  12. How do you convert string to list and vice versa?
  13. What is the find() and index() method?
  14. What is the difference between find() and index()?

Built-in Functions & Modules

  1. What are some commonly used built-in functions?
  2. What is the difference between len(), max(), and min()?
  3. What does zip() do?
  4. What is the range() function?
  5. What is the sorted() function?
  6. What is the all() and any() function?
  7. What is the sum() and abs() function?
  8. What is a module and how do you import it?
  9. What is the difference between import and from...import?
  10. What is the __name__ variable?
  11. What are some commonly used modules (os, sys, datetime, random)?
  12. How do you install external modules using pip?
  13. What is a virtual environment and why is it important?
  14. What is the dir() function?
  15. What is the help() function?
  16. What is the id() function?
  17. What is the hash() function?
  18. What is the isinstance() and issubclass() function?

Collections & Data Structures

  1. What is the difference between list.sort() and sorted()?
  2. What is the collections module?
  3. What are namedtuples?
  4. What is defaultdict?
  5. What is Counter and how is it used?
  6. What is deque and when should you use it?
  7. What is OrderedDict?
  8. What are the time complexities of list, tuple, set, and dict operations?
  9. What is a heap and how do you use the heapq module?
  10. What is a priority queue?

Debugging & Best Practices

  1. What is debugging and what are common techniques?
  2. How do you use print statements for debugging?
  3. What is the pdb module?
  4. What are unit tests and why are they important?
  5. What is docstring and how do you write it?
  6. What are assertions and how do you use them?
  7. What is logging in Python?
  8. What are the different logging levels?
  9. What is PEP 257 (docstring conventions)?
  10. What are code reviews?

Functional Programming

  1. What is functional programming?
  2. What is recursion and what are its limitations?
  3. What is a closure?
  4. What are decorators in Python?
  5. How do you create and use decorators?
  6. What are function decorators vs class decorators?
  7. How do you create a decorator with arguments?
  8. What is functools.wraps?
  9. What are built-in decorators like @staticmethod, @classmethod, @property?

Performance & Optimization

  1. What is list comprehension vs loops (performance)?
  2. What is the difference between deep copy and shallow copy?
  3. How do you create a copy of a list?
  4. What is memory management in Python?
  5. What is garbage collection?
  6. How do you measure code performance?
  7. What is Big O notation?
  8. What are common time complexities?
  9. How do you optimize Python code?

Coding Scenarios & Algorithms

  1. How do you swap two variables without using a temporary variable?
  2. How do you find the second largest number in a list?
  3. How do you remove duplicates from a list?
  4. How do you reverse a string or list?
  5. How do you check if a number is prime?
  6. How do you flatten a nested list?
  7. How do you find common elements in two lists?
  8. How do you count occurrences of an element in a list?
  9. How do you check if a string is a palindrome?
  10. How do you implement binary search?
  11. How do you implement linear search?
  12. How do you implement bubble sort?
  13. How do you implement merge sort?
  14. How do you implement quick sort?
  15. How do you find the factorial of a number?
  16. How do you find Fibonacci series?
  17. How do you check if a number is palindrome?
  18. How do you find the GCD of two numbers?
  19. How do you find the LCM of two numbers?
  20. How do you create a matrix and perform operations?

Regular Expressions

  1. What is regular expressions (regex)?
  2. How do you import the regex module?
  3. What are common regex patterns?
  4. What does the re.match() function do?
  5. What does the re.search() function do?
  6. What does the re.findall() function do?
  7. What does the re.sub() function do?
  8. What is the difference between match and search?
  9. What are character classes in regex?
  10. What are quantifiers in regex?

Web Scraping & APIs

  1. What is web scraping and is it legal?
  2. What libraries are used for web scraping?
  3. What is BeautifulSoup?
  4. What is Selenium?
  5. How do you make HTTP requests in Python?
  6. What is REST API?
  7. How do you parse JSON in Python?
  8. What is the requests library?

Working with Data

  1. What is JSON and how do you work with it?
  2. How do you read and write JSON files?
  3. What is CSV and how do you work with it?
  4. What is the CSV module?
  5. What is pandas library used for?
  6. What are DataFrames in pandas?
  7. What is NumPy?

Advanced Concepts

  1. What is threading in Python?
  2. What is the difference between threading and multiprocessing?
  3. What is a context manager?
  4. How do you create a custom context manager?
  5. What is the __enter__ and __exit__ method?
  6. What is pickle in Python?
  7. What is serialization and deserialization?
  8. What are iterables and iterators?
  9. What is the __iter__ and __next__ method?
  10. What is the difference between iterable and iterator?
  11. What are asynchronous functions?
  12. What is async and await?
  13. What is the asyncio module?
  14. What is type checking in Python?
  15. What are union types and optional types?
Previous Post Next Post