Interview

Real questions from my recent Python Developer interview

Top 10 Python Interview Questions and Answers

So you’ve got a Python interview coming up? I’ve been there, and I know that feeling of wanting to make sure you really understand the fundamentals. Over the years, I’ve noticed the same questions keep popping up in interviews, and honestly, they’re asked for good reasons—they reveal how well you actually understand Python, not just whether you can Google syntax. Let me walk you through the questions I see most often, along with explanations that actually make sense (no textbook jargon, I promise). 1. What Makes Python… Python? You know what’s funny? This seems like such a basic question, but it’s actually the interviewer’s way of seeing if you understand why we use Python in the first place. Here’s the thing—Python was designed to be readable. Like, really readable. When Guido van Rossum created it, he wanted code that you could almost read like English. And it worked! You don’t need semicolons everywhere, you don’t need to declare types for every variable, and honestly, after coding in Python, going back to other languages feels a bit verbose. Python runs your code line by line (that’s the “interpreted” part), which makes debugging so much easier. You can literally open up a terminal, type python, and start playing around. No compilation step, no ceremony. The dynamic typing thing? That means you can just write x = 5 and later x = “hello” And Python’s totally cool with it. Some people find this scary, but I find it liberating for rapid prototyping. 2. Lists vs Tuples—What’s the Big Deal? Okay, so this one trips people up because lists and tuples look so similar. But trust me, the difference matters. Think of it this way: a list is like a shopping list you can edit—cross things off, add new items, rearrange stuff. A tuple is like a GPS coordinate—once it’s (40.7128, -74.0060), it stays that way. Lists are packed with methods—you can append, remove, extend, you name it. Tuples? Not so much. They’re simpler, faster, and use less memory precisely because they can’t change. I use tuples when I want to make it crystal clear that this data shouldn’t be modified. Like coordinates, RGB color values, or database records. It’s a signal to other developers (or future me) that says, “hey, don’t mess with this.” 3. The GIL—Python’s Weird Little Secret Alright, this is where things get interesting. The Global Interpreter Lock (GIL) is one of those things that sounds way scarier than it actually is, but you should definitely understand it. Here’s the deal: Python has this lock that says “only one thread can execute Python code at a time.” Yes, even on your fancy 16-core processor. I know, I know—it sounds crazy in 2025, right? But here’s why it’s not actually the apocalypse: if your code is waiting around for stuff (downloading files, reading from disk, making API calls), the GIL doesn’t really matter. While one thread waits, another can run. It’s only when you’re crunching numbers non-stop that you run into issues. When I hit GIL limitations, here’s what I do: The GIL exists because it made Python’s memory management so much simpler to implement. Is it perfect? No. But it’s a trade-off that’s worked out pretty well for most use cases. 4. __str__ vs __repr__—Two Sides of the Same Coin This one’s actually kind of elegant once you get it. These methods control how your objects look when you print them, but they’re meant for different audiences. __str__ is for humans. It’s what shows up when you print something or convert it to a string. Make it friendly and readable. __repr__ is for developers. It should give you enough info to recreate the object. When you’re debugging at 2 AM, you’ll thank yourself for a good __repr__. Pro tip: if you only define __repr__, Python will use it for both. But if you care about user experience, define both. 5. Decorators—Fancy Function Wrappers Decorators sound intimidating, but they’re actually just a clean way to wrap functions with extra behavior. Once you “get” them, you’ll start seeing uses everywhere. Think of it like gift wrapping. You have a present (your function), and you wrap it in paper (the decorator) that adds something extra—maybe timing, logging, or checking permissions. That @timer_decorator line? It’s just Python shorthand. Without it, you’d write slow_function = timer_decorator(slow_function), which is way less pretty. I use decorators all the time for things like checking if a user is logged in, caching expensive function calls, or (like above) timing how long things take. They keep your actual function code clean while adding functionality. 6. List Comprehensions vs Generators—Memory Matters Here’s a real-world scenario: you need to process a million records. Do you load them all into memory at once, or process them one at a time? That’s basically the list vs generator question. The difference? That list comprehension (square brackets) creates all 1000 numbers immediately and stores them. The generator (parentheses) creates them lazily, one at a time, as needed. I learned this the hard way when I tried to load a 2GB CSV file into a list and watched my program crash. Switching to a generator? Smooth sailing. Use list comprehensions when you need the entire list, such as to access items randomly or iterate multiple times. Use generators when you’re dealing with large datasets or when you only need to go through the data once. Your RAM will thank you. 7. Static Methods vs Class Methods—The Identity Crisis These two decorators confused me for the longest time, so let me break it down in a way that finally made sense to me. Static methods are like the roommate who keeps to themselves—they don’t care about the class or any instances. They’re just utility functions that happen to live there because they’re related. Think of them as helper functions. Class methods get passed the class itself (that cls parameter), so they can access class-level stuff and are great for alternative constructors. Like if you want to create

Top 10 Python Interview Questions and Answers Read More »

Real questions from my recent Python Developer interview

Interview Questions I Faced for a Python Developer

Hi guys, recently I gave an interview at a startup company. I can’t reveal their name, but I am posting the questions they asked me. It was a Python Developer interview, but they also asked questions from Django, MySQL, and JavaScript. 1. What is a Django Signal? A Django signal is a messaging system that allows certain parts of your application to send notifications (signals) when an action occurs, and other parts of the app can listen and react to those events automatically. In Other words:Signals let you run some code whenever something happens in Django (like after a user is saved, deleted, or logged in). 2. How does map() work in JavaScript? map() is an array method that loops through each element, applies a function, and returns a new array without modifying the original. Example: 3. What is Django ORM? Django ORM is Object Relational Mapper that lets you interact with the database using Python instead of SQL. Example: 4. What is a Trigger in SQL? A trigger is an automatic block of SQL code that runs when you insert, update, or delete data in a table. Used for logs, validation, and audits. 5. Example of One-to-Many relationship in Django ORM 6. Difference between REST API and SOAP API SOAP is a strict, XML-based protocol with built-in security REST is a lightweight, flexible API style using JSON. REST SOAP Flexible Strict JSON/XML XML Only Lightweight Heavy No WSDL Uses WSDL Quick Slower Keep it short in interviews. 7. How do you authenticate a REST API? You can authenticate REST APIs using: Mention JWT, it’s the most popular. 8. DDL – Data Definition Language DDL (Data Definition Language) is a type of SQL command used to define, create, modify, and delete database structures such as tables, indexes, schemas, and views. Commands: Deals with tables, columns, and schemas. 9. DML – Data Manipulation Language DML (Data Manipulation Language) is a set of SQL commands used to insert, update, delete, and retrieve data from a database. Commands:  Changes data, not structure. 10. How you write a custom SQL query in django Django provides a connection.cursor() functionality, and by using this cursor, we can write and execute custom SQL queries directly. For example:

Interview Questions I Faced for a Python Developer Read More »

Top Django, SQL, and AWS Interview Questions and Answers

Top Django, SQL, and AWS Interview Questions and Answers

If you are preparing for Python/Django backend interviews, then you’ll not only face questions on Django itself but also on SQL, APIs, caching, and cloud (AWS). Therefore, in this blog, I’ve compiled some of the most frequently asked questions along with clear and concise answers. However, these examples will help you understand the concepts better and prepare more effectively for your next interview. My advice is to prepare more questions in SQL because, for Django developers, it is often difficult to learn SQL due to relying heavily on the ORM. Therefore, practicing SQL separately will strengthen your backend fundamentals and give you more confidence in interviews. 1. What is the Longest Substring Problem? The longest substring problem usually refers to finding the longest substring without repeating characters. def longest_substring(s): seen = set() left = 0 start = 0 max_len = 0 for right in range(len(s)): while s[right] in seen: # shrink window if duplicate found seen.remove(s[left]) left += 1 seen.add(s[right]) if (right – left + 1) > max_len: max_len = right – left + 1 start = left # track start index of longest substring return s[start:start + max_len] # Example print(longest_substring(“abcabcbb”)) # Output: “abc” 2. What are the Types of Indexing in Databases? A database technique that speeds up query performance by creating data pointers: 3. How Do I Write the Longest SQL Query? This is a trick question — instead of “long queries,” interviewers expect optimized queries. 4. How Do You Make Fast APIs in Django Rest Framework (DRF)? Ways to optimize DRF APIs: 5. Can an Anonymous User Store Cart Items? An anonymous user’s cart items can be stored using sessions or cookies. The cart data (like product IDs and quantities) is kept in the session or browser storage until the user logs in. Once they log in, the session/cart data is merged into the user’s permanent cart stored in the database. 6. How Do You Store Frequently Accessed Product Images Efficiently? 7. What is Middleware in Django? Middleware is a layer between the request and the response. These are predefined in django: Authentication, Session, CSRF, and Security headers. Custom Middleware Example: class SimpleMiddleware: def __init__(self, get_response): self.get_response = get_response def __call__(self, request): print(“Before View:”, request.path) response = self.get_response(request) print(“After View:”, response.status_code) return response register in settings like settings.py → MIDDLEWARE = [‘myapp.middleware.SimpleMiddleware’, …] 8. How Do You Optimize Django ORM Queries? 9. How Do You Write Raw SQL Queries in Django? Two main ways of user raw or user cursor connection: users = UserProfile.objects.raw(“SELECT * FROM user WHERE active = %s”, [True]) from django.db import connection with connection.cursor() as cursor: cursor.execute(“SELECT id, name FROM user WHERE active = %s”, [True]) rows = cursor.fetchall() 10. What AWS Services Have You Used? 11. What is Load Balancing in AWS? Load balancing distributes incoming traffic across multiple servers. AWS provides Elastic Load Balancer (ELB): 12. What are the Types of JOIN Queries in SQL? In SQL, JOINs combine rows from two or more tables based on related columns. They allow you to fetch meaningful data by linking multiple tables together. Different types of JOINs define how records from one table are matched with records from another. 13. How Does LEFT JOIN Work? LEFT JOIN returns all rows from the left table and matching rows from the right. Non-matching → NULL. Example: SELECT e.name, d.dept_name FROM Employees e LEFT JOIN Departments d ON e.dept_id = d.id; 14. How Do You Implement Push Notifications in Django? 15. What is Redis, and How Did You Use It? Redis serves as a high-performance caching and message broker.Use cases in Django: Example (Django cache): from django.core.cache import cache def get_product(pid): key = f”product:{pid}” product = cache.get(key) if not product: product = Product.objects.get(id=pid) cache.set(key, product, 3600) return product Preparing for Python/Django backend interviews requires a balance of theory and practical knowledge. While Django and its ORM simplify a lot of work, interviewers often test your understanding of SQL, system design, caching, and cloud services like AWS. Therefore, practice coding problems, revisit core SQL queries, and explore concepts like load balancing, middleware, and caching. With consistent preparation, you’ll not only perform well in interviews but also become a more confident backend developer. See my previous Python Interview question.

Top Django, SQL, and AWS Interview Questions and Answers Read More »

python interview question

Top 30 Python Interview Questions and Answers (2025)

In this blog, I’ll share 30+ real-world Python interview questions and answers — carefully curated from actual company interviews, including those from startups and top tech firms. Whether you’re just starting out or preparing for your next big opportunity, these questions will help you build confidence, sharpen your problem-solving skills, and stand out in competitive hiring rounds. Moreover, they are tailored to match what companies are asking in 2025, making this a practical and up-to-date resource for your next Python coding interview. I’ve included beginner to advanced Python concepts, covering OOP, data structures, algorithms, and Python libraries commonly asked about by recruiters. If you find this helpful, comment below—I’ll post an advanced Python Q&A series next! 1. What is the Difference Between a List and a Tuple? l = [1, 2, 3] # list t = (1, 2, 3) # tuple 2. Difference Between List Comprehension and Dict Comprehension # List squares = [x*x for x in range(5)] # Dict square_dict = {x: x*x for x in range(5)} 3. What is a Lambda Function in Python? A Lambda function in Python is a small, anonymous function that can have any number of arguments but can only have one expression. It’s a concise way to create simple functions without using the def keyword. add = lambda a, b: a + b 4. Examples of Mutable and Immutable Datatypes in Python Basic Difference: # Value equality with == a = [1, 2, 3] b = [1, 2, 3] print(a == b) # True – same values print(a is b) # False – different objects # Identity with is c = a print(a is c) # True – same object print(a == c) # True – same values 5. What is the Difference Between is and ==? a = [1, 2] b = a c = [1, 2] a is b # True a == c # True a is c # False 6. How Are Variables and Objects Stored in Python? In Python, variables and objects are stored using a combination of namespaces and memory management through references. Objects → Stored in Heap MemoryVariables (Names) → Stored in Stack Memory 7. What is a Decorator in Python? A function that modifies another function without changing its structure. def decorator(func): def wrapper(): print(“Before function”) func() print(“After function”) return wrapper @decorator def greet(): print(“Hello”) greet() 8. Difference Between Generators and Iterators def gen(): yield 1 yield 2 9. Difference Between Pickling and Unpickling? import pickle data = pickle.dumps({‘a’: 1}) obj = pickle.loads(data) 10. Difference Between Shallow Copy and Deep Copy import copy copy.copy(obj) # shallow copy.deepcopy(obj) # deep 11. Multiprocessing vs Multithreading in Python 12. How is Memory Managed in Python? Memory management in Python is handled by the Python memory manager, which includes a private heap, automatic garbage collection, and dynamic memory allocation using reference counting and a cyclic garbage collector. 13. What is the Garbage Collector in Python? The garbage collector in Python is a built-in mechanism that automatically frees up memory by reclaiming objects that are no longer in use, primarily using reference counting and cyclic garbage collection. 14. What is GIL (Global Interpreter Lock)? A mutex that allows only one thread to execute Python bytecode at a time, preventing race conditions in CPython. 15. What is a First-Class Function in Python? First-Class Function: In Python, functions are first-class objects, meaning they can be treated like any other data type. They can be: This allows for powerful programming patterns like higher-order functions, decorators, and functional programming techniques. Functions have the same privileges as other objects in Python. 16. What is a Closure in Python? Closure: A closure is a function that captures and retains access to variables from its outer (enclosing) scope, even after the outer function has finished executing. The inner function “closes over” these variables, keeping them alive in memory. def outer_function(message): def inner_function(): print(f”Message: {message}”) return inner_function # Create a closure my_closure = outer_function(“Hello from closure!”) # Call the inner function my_closure() Key characteristics: This enables data encapsulation and creates functions with persistent local state. 17. Different Ways to Read/Write a File in Python # Read with open(‘file.txt’, ‘r’) as f: data = f.read() # Write with open(‘file.txt’, ‘w’) as f: f.write(“Hello”) 18. What is a Context Manager in Python? Context Manager: An object that defines methods to be used with Python’s with statement. It ensures proper resource management by automatically handling setup and cleanup operations, even if an exception occurs. Key Methods: Purpose: Provides a clean way to manage resources like files, database connections, or locks by ensuring they are properly acquired and released, preventing resource leaks and ensuring cleanup code always runs. 19. Types of Inheritance in Python 20. Difference Between Abstraction and Encapsulation Abstraction: The process of hiding complex implementation details and showing only the essential features of an object. It focuses on what an object does rather than how it does it. Achieved through abstract classes, interfaces, and methods that provide a simplified view of functionality. Encapsulation: The bundling of data (attributes) and methods that operate on that data within a single unit (class), while restricting direct access to internal components. It focuses on hiding the internal state and requiring interaction through well-defined interfaces using access modifiers (private, protected, public). Key Difference: Abstraction is about simplifying complexity by hiding unnecessary details, while encapsulation is about protecting data integrity by controlling access to internal components. 21. What is Polymorphism in Python? Polymorphism: The ability of different objects to respond to the same interface or method call in their specific way. It allows objects of different types to be treated uniformly while exhibiting different behaviors based on their actual type. Key Characteristics: Types in Python: This enables writing generic code that can work with various object types without knowing their specific implementation details. 22. What is Function Overloading? Multiple functions with the same name but different parameters (Not natively supported in Python). 23. What is Function Overriding? Function Overriding: The ability of a child class

Top 30 Python Interview Questions and Answers (2025) Read More »

Scroll to Top