Python Interview Summary
Python Interview Summary
Object-Oriented Programming is a way of organizing code using objects that combine data
(attributes) and behavior (methods). Classes help us model real-world entities, support code
reuse through inheritance, and make code more modular and easier to maintain.
Magic methods are special methods with double underscores that allow us to define how objects
behave with built-in functions and operators. Examples include __init__ (constructor), __str__
(string representation for print), __repr__ (official string representation), and __len__,
__add__.
__str__ is meant to return a user-friendly string representation of an object, usually for display
to end users.
__repr__ is meant to return an unambiguous representation of the object, often used for
debugging, and ideally it should look like valid Python code to recreate the object.
Decorators are a way to modify or extend the behavior of functions or methods without changing
their actual code. They are often used for logging, authentication, or measuring execution time.
Exception handling allows a program to gracefully handle unexpected errors instead of crashing.
We can catch and manage errors, provide fallback behavior, or give meaningful error messages
to the user.
✅ What is the difference between file handling for CSV and JSON?
CSV files store data as plain text in tabular form, mainly for simple structured data. JSON is
used for hierarchical or nested data structures, commonly used in web APIs because it maps
directly to Python dictionaries.
Unit testing helps verify that individual components work as intended, catching bugs early.
unittest is Python’s built-in testing framework, while pytest is a more flexible, user-friendly
framework that supports advanced features like fixtures and parameterized tests.
Multithreading uses multiple threads within the same process; it is useful for I/O-bound tasks but
limited by Python’s Global Interpreter Lock (GIL).
Multiprocessing runs separate processes with separate memory spaces, useful for CPU-bound
tasks as it can truly run code in parallel.
Sorting helps in organizing data for efficient searching and processing. Common algorithms
include quicksort, mergesort, and bubble sort (though bubble sort is inefficient and mainly used
for learning).
String manipulation refers to tasks like concatenation, slicing, searching, and formatting strings.
It’s important for data processing, user input validation, and preparing output in applications.
Time complexity measures how the runtime of an algorithm increases with input size.
Space complexity measures how memory usage increases with input size.
Both are important for designing scalable and efficient programs.
A REST API is a way for systems to communicate over HTTP using stateless requests and
standard methods like GET, POST, PUT, DELETE. It enables different software to interact in a
consistent way.
✅ Why are status codes important in REST APIs?
Status codes let clients know the result of their request. For example, 200 means success, 400
means bad request, 401 means unauthorized, 404 means not found, and 500 means server error.
An operation is idempotent if performing it multiple times has the same effect as performing it
once. In payments, this prevents duplicate charges if a request is retried due to network errors.
✅ What is JWT?
JSON Web Token (JWT) is a compact, self-contained way to represent information securely
between parties, often used for authentication and authorization in web applications.
Databases store application data persistently. ORM (Object Relational Mapping) allows
developers to interact with databases using objects instead of writing raw SQL, which makes
code more readable and maintainable.
💡 Security basics
✅ What is hashing, and where is it used?
Hashing transforms data into a fixed-size value, usually for secure storage or verification. It is
commonly used for storing passwords and checking data integrity.
✅ What is encryption?
Encryption transforms data so that only authorized parties can read it. It protects data
confidentiality during storage or transmission.
✅ Why is input validation important?
Input validation prevents harmful data from entering the system, reducing risks like SQL
injection, code injection, or unexpected crashes.
Examples include using HTTPS, validating input, proper authentication and authorization, rate
limiting, and avoiding sensitive data exposure in logs or error messages.
✅ Next Step
• Review and practice saying these answers out loud.
• Keep them short and confident — interviewers prefer clear, to-the-point responses.
✅ If you'd like, I can also prepare example coding problems based on these topics (just
conceptual problems, no solutions), so you can practice explaining your approach. Want me to
do that?