Python Interview Questions for Freshers 2026: Core Language, Data Structures and Coding

Prepare concise, accurate answers to Python fresher interview questions, then test your object model on mutable defaults, complexity, coding patterns and output traps.

Prashant Jain

KnowledgeGate AI educator

Updated 15 Jul 20265 min read

Python interviews for freshers rarely begin with a large application. They begin with small questions that reveal whether you understand objects, references and how Python executes code. Miss that mental model and a simple output question can make an otherwise good answer look uncertain.

Prepare short definitions, but connect each one to behaviour. This guide covers the core language, data structures and coding staples, then works through the mutable-default trap that interviewers use to test whether your understanding is real.

How Python fresher interviews usually go

Expect rapid concept checks followed by one or two snippets where you explain the output. An interviewer may ask for the difference between a list and tuple, then immediately show a shared-list mutation. They are checking whether your definitions survive code.

Use a three-part answer: state the rule, give a tiny example, then name the practical consequence. For is versus ==, for example, say that is checks object identity, == checks value equality, and value comparison normally needs ==. That is stronger than reciting two definitions without a decision rule.

Core Python questions you must know

What is mutable versus immutable? A mutable object can change in place. Lists, dictionaries and sets are mutable; integers, strings and tuples are immutable. Rebinding a name is different from mutating its object.

What is `is` versus `==`? is checks whether two names refer to one object. == checks whether their values compare equal. Use is for singletons such as None, and == for ordinary value comparison.

What is shallow versus deep copy? A shallow copy creates a new outer container but keeps references to nested objects. A deep copy recursively copies the nested object graph. Explain why a shallow copy of [[1], [2]] still shares its inner lists.

What is the GIL? In a standard GIL-enabled CPython process, the Global Interpreter Lock allows one thread at a time to execute Python bytecode. Threads therefore do not normally parallelise CPU-bound Python work, but they remain useful when tasks wait for network or file I/O. Processes are the usual choice for CPU-bound parallel work.

What are `*args` and `kwargs?** args` collects extra positional arguments into a tuple. `*kwargs` collects extra named arguments into a dictionary. They help write wrappers and flexible APIs, but explicit parameters are clearer when the interface is fixed.

List, tuple, set or dict? Choose a list for ordered mutable values, a tuple for a fixed immutable record, a set for unique values and fast average membership, and a dictionary for key-to-value lookup. The Python Data Structures guide develops the operation costs behind those choices.

List comprehension versus generator expression? A list comprehension builds the complete list immediately. A generator expression produces values lazily, saving memory when one pass is enough.

What is a decorator? A decorator takes a callable and returns a wrapped or modified callable. The @name syntax applies it at definition time.

Why use `if __name__ == "__main__"`? Code inside the guard runs when the file is executed directly, but not when it is imported as a module. It separates reusable definitions from script entry behaviour.

Worked example: the mutable default argument

Use this code exactly:

def add(x, lst=[]):
    lst.append(x)
    return lst

print(add(1))
print(add(2))
print(add(3, []))

The default [] is created once, when the function is defined. Calls that omit lst reuse that same object.

  1. add(1) receives the default list. Appending 1 makes it [1], so the first line printed is [1].

  2. add(2) receives the same default list. Appending 2 changes it from [1] to [1, 2], so the second line is [1, 2].

  3. add(3, []) receives a fresh list supplied by the caller. It becomes [3], so the third line is [3].

The exact output is:

[1]
[1, 2]
[3]

The standard fix is:

def add(x, lst=None):
    if lst is None:
        lst = []
    lst.append(x)
    return lst

Now every call that omits lst creates a fresh list during that call. Notice the correct use of is None: here identity is exactly what we mean.

one shared default-list object bound to the parameter lst at function-definition time. Draw arrows from the first two calls both mutating it (-> [1] -> [1, 2]); draw the third call pointing to a separate fresh [] (-> [3]). Print the three output lines [1], [1, 2], [3].

Data structures and complexity answers

Dictionary and set membership are average O(1) because they are hash-backed. List membership is O(n) because it may scan every element. If an outer loop performs list membership for each of n values, the pattern can become O(n^2); replacing the lookup collection with a set can make the average total O(n).

A tuple can be a dictionary key only if all objects it contains are hashable. (1, "A") works, while ([1], "A") does not because a list is mutable and unhashable.

Strings are immutable. Repeated result += piece can create successive string objects and copy accumulated content. Collect pieces and use "".join(pieces) when building a substantial string in a loop.

Practise explaining both the rule and its cost in the Python Programming course. Interviewers often follow “which structure?” with “why is it faster?”

Coding-round staples in Python

Aim to explain the idea before writing the one-liner:

  • Reverse a string or list with value[::-1].

  • Test a palindrome with value == value[::-1] after applying any required normalisation.

  • Test an anagram with collections.Counter(a) == collections.Counter(b).

  • Find the first non-repeating character by counting first, then scanning in original order.

  • Solve two-sum by storing each seen value and its index in a dictionary while checking the required complement.

  • Compute Fibonacci without repeated work by iterating with two variables or using memoisation.

  • Flatten one level of nesting with [item for group in nested for item in group].

Do not force a Pythonic shortcut when it hides the requested algorithm. If the interviewer asks you to demonstrate two pointers or recursion, show that method and discuss its complexity.

Explain-the-output rapid fire

Why is `0.1 + 0.2 == 0.3` false? These decimal fractions do not have exact finite binary floating-point representations, so the computed values differ slightly. This behaviour follows floating-point representation, not randomness.

What is wrong with `[[]] * 3`? It creates a list containing three references to the same inner list. Mutating one inner list is visible at all three positions. This is aliasing, not three independent nested lists.

Is `bool` related to `int`? Yes. In Python, bool is a subclass of int, and True and False behave numerically like 1 and 0 in arithmetic contexts. Clear code still uses them as booleans.

Why can `a is b` look true for small integers? An implementation may reuse or intern some immutable objects. That identity is an implementation detail, not a language guarantee for comparing numeric values. Use ==.

Work more of these snippets in Python Output-Based Questions. Say which conclusions are language rules and which depend on an implementation.

Short version and next step

Hold the objects-and-references model, know copy semantics and the GIL, and connect each data-structure choice to its operations. Then rehearse output answers aloud: rule, trace, result.

KnowledgeGate has about 450 published Python questions across core language and output topics. After concept practice, use the Placement Preparation catalogue and rehearse under time with the Mera Placement Hoga Anushasan bundle. A fresher answer does not need to sound senior. It needs to be precise, testable and honest.