November 22, 2025
11 min read

Junior Backend Developer (Python) Interview Questions: Complete Guide

interview
career-advice
job-search
entry-level
Junior Backend Developer (Python) Interview Questions: Complete Guide
MB

Milad Bonakdar

Author

Master Python backend development with essential interview questions covering Python fundamentals, Django/Flask, databases, APIs, and more. Perfect preparation for junior backend developer interviews.


Introduction

This comprehensive guide contains 30 essential interview questions covering Python backend development. These questions are designed to help junior backend developers prepare for interviews by covering key concepts in Python, web frameworks (Django/Flask), databases, and general backend architecture. Each question includes a detailed answer, rarity assessment, and difficulty rating.

Whether you're just starting your career or looking to switch to backend development, this guide will help you build confidence and master the fundamentals.


Python Fundamentals (10 Questions)

1. What is the difference between list and tuple in Python?

Answer:

  • list: Mutable (can be changed), defined with square brackets [], slower than tuples.
  • tuple: Immutable (cannot be changed), defined with parentheses (), faster than lists, can be used as dictionary keys.

Example:

# List
my_list = [1, 2, 3]
my_list[0] = 10  # Allowed

# Tuple
my_tuple = (1, 2, 3)
# my_tuple[0] = 10  # TypeError: 'tuple' object does not support item assignment

Rarity: Common Difficulty: Easy


2. Explain the difference between is and ==

Answer:

  • ==: Checks for value equality (do the objects have the same value?).
  • is: Checks for reference equality (do the variables point to the exact same object in memory?).

Example:

a = [1, 2, 3]
b = [1, 2, 3]

print(a == b)  # True (values are same)
print(a is b)  # False (different objects in memory)

c = a
print(a is c)  # True (same object)

Rarity: Common Difficulty: Easy


3. What are Python decorators and how do they work?

Answer: A decorator is a design pattern in Python that allows a user to add new functionality to an existing object without modifying its structure. Decorators are usually called before the definition of a function you want to decorate.

Example:

def my_decorator(func):
    def wrapper():
        print("Something is happening before the function is called.")
        func()
        print("Something is happening after the function is called.")
    return wrapper

@my_decorator
def say_hello():
    print("Hello!")

say_hello()
# Output:
# Something is happening before the function is called.
# Hello!
# Something is happening after the function is called.

Rarity: Common Difficulty: Medium


4. What is the difference between args and kwargs?

Answer:

  • *args: Allows you to pass a variable number of non-keyword arguments to a function. It collects them into a tuple.
  • **kwargs: Allows you to pass a variable number of keyword arguments to a function. It collects them into a dictionary.

Example:

def example_function(*args, **kwargs):
    print("args:", args)
    print("kwargs:", kwargs)

example_function(1, 2, 3, name="Alice", age=30)
# Output:
# args: (1, 2, 3)
# kwargs: {'name': 'Alice', 'age': 30}

Rarity: Common Difficulty: Easy


5. Explain list comprehensions

Answer: List comprehensions provide a concise way to create lists. Common applications are to make new lists where each element is the result of some operations applied to each member of another sequence or iterable, or to create a subsequence of those elements that satisfy a certain condition.

Example:

# Traditional way
squares = []
for x in range(10):
    squares.append(x**2)

# List comprehension
squares = [x**2 for x in range(10)]

Rarity: Common Difficulty: Easy


6. What are generators and the yield keyword?

Answer: Generators are a simple way of creating iterators. They are functions that return an object (iterator) which we can iterate over (one value at a time). The yield keyword is used like return, except the function will return a generator.

Example:

def simple_generator():
    yield 1
    yield 2
    yield 3

for value in simple_generator():
    print(value)
# Output: 1, 2, 3

Benefits: Memory efficient (lazy evaluation).

Rarity: Medium Difficulty: Medium


7. How does memory management work in Python?

Answer: Python uses a private heap space to manage memory. All Python objects and data structures are located in a private heap. The programmer does not have access to this private heap. The interpreter takes care of this Python private heap. Python also has a built-in garbage collector, which recycles all the unused memory and so that it can be made available to the heap space.

Rarity: Medium Difficulty: Medium


8. What is the Global Interpreter Lock (GIL)?

Answer: The Global Interpreter Lock (GIL) is a mutex that protects access to Python objects, preventing multiple threads from executing Python bytecodes at once. This lock is necessary mainly because CPython's memory management is not thread-safe.

Impact: It limits multi-threaded Python programs to run on a single CPU core, which can be a bottleneck for CPU-bound tasks.

Rarity: Medium Difficulty: Hard


9. Explain the difference between deep copy and shallow copy

Answer:

  • Shallow Copy: Creates a new object which stores the reference of the original elements. So, a shallow copy doesn't create a copy of nested objects, instead it just copies the reference of nested objects.
  • Deep Copy: Creates a new object and recursively adds the copies of nested objects present in the original elements.

Example:

import copy

original = [[1, 2, 3], [4, 5, 6]]
shallow = copy.copy(original)
deep = copy.deepcopy(original)

original[0][0] = 'X'
print(shallow[0][0]) # 'X' (affected)
print(deep[0][0])    # 1 (unaffected)

Rarity: Medium Difficulty: Medium


10. What are Python's built-in data types?

Answer:

  • Numeric: int, float, complex
  • Sequence: list, tuple, range
  • Text: str
  • Mapping: dict
  • Set: set, frozenset
  • Boolean: bool
  • Binary: bytes, bytearray, memoryview

Rarity: Common Difficulty: Easy


Web Frameworks (Django/Flask) (10 Questions)

11. Compare Django and Flask

Answer:

  • Django: "Batteries-included" framework. Includes ORM, authentication, admin panel, etc. Good for large, complex applications. Follows MVT (Model-View-Template) pattern.
  • Flask: Micro-framework. Minimalistic, flexible. You choose the tools you want (ORM, auth, etc.). Good for smaller apps, microservices, or when you need fine-grained control.

Rarity: Common Difficulty: Easy


12. What is the MVC pattern (and MVT in Django)?

Answer:

  • MVC (Model-View-Controller): Architectural pattern that separates an application into three main logical components: the model (data), the view (user interface), and the controller (processes inputs).
  • MVT (Model-View-Template): Django's variation.
    • Model: Data structure (database).
    • View: Business logic (similar to Controller in MVC).
    • Template: Presentation layer (similar to View in MVC).

Rarity: Common Difficulty: Medium


13. Explain Django ORM

Answer: Django ORM (Object-Relational Mapping) allows you to interact with your database, like SQLite, PostgreSQL, and MySQL, using Python code instead of SQL. You define your data models as Python classes, and Django handles the database table creation and queries.

Example:

# Model
class Person(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)

# Query
Person.objects.filter(first_name="John")

Rarity: Common Difficulty: Medium


14. What is a migration in Django?

Answer: Migrations are Django's way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema. They are designed to be mostly automatic, but you'll need to know when to make migrations, when to run them, and the common problems you might run into.

Commands:

  • makemigrations: Creates new migrations based on model changes.
  • migrate: Applies migrations to the database.

Rarity: Common Difficulty: Easy


15. How does Flask handle routing?

Answer: Flask uses the @app.route() decorator to bind a function to a URL.

Example:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

@app.route('/user/<username>')
def show_user_profile(username):
    return f'User {username}'

Rarity: Common Difficulty: Easy


16. What are Flask Blueprints?

Answer: Blueprints are a way to organize your Flask application into modules. They allow you to group related routes, templates, and static files together. This is essential for scaling Flask applications.

Rarity: Medium Difficulty: Medium


17. Explain the concept of Middleware in Django

Answer: Middleware is a framework of hooks into Django's request/response processing. It's a light, low-level "plugin" system for globally altering Django's input or output. Each middleware component is responsible for doing some specific function.

Examples: AuthenticationMiddleware, SessionMiddleware, CsrfViewMiddleware.

Rarity: Medium Difficulty: Medium


18. How do you handle sessions in Flask?

Answer: Flask uses a signed cookie to store the session contents. The user can look at the contents of the cookie but cannot modify it, unless they know the secret key used for signing.

Example:

from flask import session

@app.route('/login', methods=['POST'])
def login():
    session['username'] = request.form['username']
    return redirect(url_for('index'))

Rarity: Medium Difficulty: Medium


19. What is the purpose of settings.py in Django?

Answer: settings.py is the main configuration file for a Django project. It contains all the configuration for the project, including database settings, installed apps, middleware, template settings, static file paths, and security keys.

Rarity: Common Difficulty: Easy


20. How do you prevent CSRF attacks in Django?

Answer: Django has built-in protection against Cross Site Request Forgery (CSRF). It uses a CSRF token that is generated for each user session. This token must be included in every POST request (usually as a hidden form field). The server verifies the token before processing the request.

Rarity: Medium Difficulty: Medium


Database & General Backend (10 Questions)

21. SQL vs NoSQL

Answer:

  • SQL (Relational): Structured data, predefined schema, tables, rows, columns. Good for complex queries and transactions (ACID). Examples: PostgreSQL, MySQL.
  • NoSQL (Non-Relational): Unstructured or semi-structured data, dynamic schema, documents, key-value pairs. Good for scalability, rapid prototyping, and large datasets. Examples: MongoDB, Redis.

Rarity: Common Difficulty: Easy


22. What is an API?

Answer: API stands for Application Programming Interface. It is a set of rules and protocols that allows different software applications to communicate with each other. In backend development, we typically build RESTful APIs or GraphQL APIs to allow frontends (web, mobile) to interact with the backend data and logic.

Rarity: Common Difficulty: Easy


23. Explain RESTful API principles

Answer:

  • Client-Server: Separation of concerns.
  • Stateless: No client context stored on the server between requests.
  • Cacheable: Responses must define themselves as cacheable or not.
  • Uniform Interface: Standardized way to communicate (HTTP methods: GET, POST, PUT, DELETE).
  • Layered System: Client cannot ordinarily tell whether it is connected directly to the end server, or to an intermediary along the way.

Rarity: Common Difficulty: Medium


24. What are HTTP status codes? Give examples.

Answer: Standard response codes given by web server servers on the internet.

  • 2xx Success: 200 OK, 201 Created.
  • 3xx Redirection: 301 Moved Permanently, 304 Not Modified.
  • 4xx Client Error: 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found.
  • 5xx Server Error: 500 Internal Server Error, 502 Bad Gateway.

Rarity: Common Difficulty: Easy


25. What is database indexing?

Answer: Indexing is a data structure technique used to quickly locate and access the data in a database. Indexes are created using a few database columns. It improves the speed of data retrieval operations on a database table at the cost of additional writes and storage space to maintain the index data structure.

Rarity: Medium Difficulty: Medium


26. Explain the concept of ACID properties in databases

Answer:

  • Atomicity: All operations in a transaction succeed or every operation is rolled back.
  • Consistency: Database properly changes states upon a successfully committed transaction.
  • Isolation: Enables transactions to operate independently of and transparent to each other.
  • Durability: Ensures that the result or effect of a committed transaction persists in case of a system failure.

Rarity: Medium Difficulty: Medium


27. What is Docker and why is it used?

Answer: Docker is a platform for developing, shipping, and running applications in containers. Containers are lightweight, portable, and self-sufficient units that include everything needed to run an application (code, runtime, system tools, libraries). It solves the "it works on my machine" problem and ensures consistency across different environments (dev, staging, prod).

Rarity: Common Difficulty: Medium


28. What is Unit Testing?

Answer: Unit testing is a software testing method where individual units or components of a software are tested. The purpose is to validate that each unit of the software code performs as expected. In Python, the unittest framework or pytest is commonly used.

Rarity: Common Difficulty: Easy


29. What is Git and why is it important?

Answer: Git is a distributed version control system. It tracks changes in source code during software development. It allows multiple developers to work on the same project simultaneously, manage different versions of the code (branches), and revert to previous states if necessary.

Rarity: Common Difficulty: Easy


30. How do you secure a backend API?

Answer:

  • Authentication: Verify who the user is (JWT, OAuth).
  • Authorization: Verify what the user is allowed to do (Roles/Permissions).
  • HTTPS: Encrypt data in transit.
  • Input Validation: Sanitize all inputs to prevent SQL injection and XSS.
  • Rate Limiting: Prevent abuse/DDoS.
  • CORS: Restrict which domains can access your API.

Rarity: Medium Difficulty: Medium

Related Posts

Recent Posts

Weekly career tips that actually work

Get the latest insights delivered straight to your inbox