DEV Community

interview pitch
interview pitch

Posted on

Python Interview Questions Freshers Often Get Wrong (With Code)

Python Interview Questions Freshers Often Get Wrong (With Code)

Python interviews for freshers usually do not begin with complicated algorithms. Instead, interviewers often ask deceptively simple questions to check whether you actually understand how Python behaves.

The problem is that many candidates memorize definitions such as "Python is dynamically typed" or "lists are mutable" without understanding what those statements mean when real code is placed in front of them.

In this article, we will look at some common Python interview questions freshers often get wrong, understand why the obvious answer may be incorrect, and walk through practical code examples.

If you are preparing for Python interviews, you can also explore more curated interview questions and coding preparation resources at InterviewPitch.com .


1. What Is the Output of This Python Code?

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

b.append(4)

print(a)
print(b)

A common fresher answer is:

[1, 2, 3]
[1, 2, 3, 4]

But that is incorrect.

The actual output is:

[1, 2, 3, 4]
[1, 2, 3, 4]

Why?

The statement:

b = a

does not create another list.

Both variables refer to the same list object in memory. Therefore, modifying the list through b also affects what you see through a.

You can verify this:

print(a is b)

Output:

True

How Do You Create a Copy?

a = [1, 2, 3]
b = a.copy()

b.append(4)

print(a)
print(b)

Output:

[1, 2, 3]
[1, 2, 3, 4]

2. What Is the Difference Between == and is?

This is one of the most frequently misunderstood Python interview questions.

Consider:

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

print(a == b)
print(a is b)

Output:

True
False

Why?

== compares values.

is checks whether two variables refer to the exact same object.

Therefore:

a == b

is True because both lists contain the same values.

But:

a is b

is False because they are two different list objects.

A good interview answer is:

== checks value equality, while is checks object identity.

3. Why Does This Function Behave Strangely?

def add_item(item, items=[]):
    items.append(item)
    return items

print(add_item("Python"))
print(add_item("Java"))

Many freshers expect:

['Python']
['Java']

Actual output:

['Python']
['Python', 'Java']

Why?

Default arguments are evaluated when the function is defined, not every time the function is called.

That means the same list is reused across calls.

Better Approach

def add_item(item, items=None):

    if items is None:
        items = []

    items.append(item)

    return items

Now:

print(add_item("Python"))
print(add_item("Java"))

Output:

['Python']
['Java']

This is an excellent example of why understanding Python behavior matters more than memorizing syntax.


4. What Is the Difference Between a List and a Tuple?

Most freshers immediately answer:

Lists are mutable, while tuples are immutable.

That answer is correct, but interviewers often expect a little more.

List Example

numbers = [10, 20, 30]

numbers[0] = 100

print(numbers)

Output:

[100, 20, 30]

Tuple Example

numbers = (10, 20, 30)

numbers[0] = 100

This produces an error because tuples cannot be modified this way.

When Would You Use a Tuple?

Tuples are useful when:

  • The collection should not be modified.
  • You want to represent fixed records.
  • You need hashable data in situations where the contents permit it.
  • You want to communicate that the sequence is conceptually fixed.

5. What Will range(5) Produce?

A surprising number of beginners answer:

1 2 3 4 5

But:

for i in range(5):
    print(i)

produces:

0
1
2
3
4

The ending value is excluded.

In general:

range(start, stop, step)

includes start but excludes stop.

Example:

for i in range(2, 10, 2):
    print(i)

Output:

2
4
6
8

6. What Is the Output?

print(bool([]))
print(bool([0]))
print(bool(""))
print(bool("False"))

Output:

False
True
False
True

The Trap

A list containing 0 is still a non-empty list. Therefore:

bool([0])

is True.

Similarly:

bool("False")

is also True because the string is not empty. Python is not evaluating the meaning of the word "False".

Common Falsy Values

  • False
  • None
  • 0
  • 0.0
  • ""
  • []
  • {}
  • ()
  • set()

7. What Is the Difference Between append() and extend()?

Using append()

numbers = [1, 2]

numbers.append([3, 4])

print(numbers)

Output:

[1, 2, [3, 4]]

Using extend()

numbers = [1, 2]

numbers.extend([3, 4])

print(numbers)

Output:

[1, 2, 3, 4]

append() adds one object to the end of the list.

extend() iterates over another iterable and adds its elements to the existing list.


8. What Happens When You Use break, continue and pass?

These three keywords are sometimes confused during interviews.

break

Stops the loop completely.

for i in range(5):

    if i == 3:
        break

    print(i)

Output:

0
1
2

continue

Skips the current iteration.

for i in range(5):

    if i == 2:
        continue

    print(i)

Output:

0
1
3
4

pass

Does nothing. It is often used as a placeholder where Python requires a statement syntactically.

def future_feature():
    pass

9. What Is the Difference Between remove(), pop() and del?

remove()

Removes a specific value.

numbers = [10, 20, 30]

numbers.remove(20)

print(numbers)

Output:

[10, 30]

pop()

Removes an item by index and returns the removed value.

numbers = [10, 20, 30]

value = numbers.pop(1)

print(value)
print(numbers)

Output:

20
[10, 30]

del

Deletes by index, slice, or even a variable binding.

numbers = [10, 20, 30]

del numbers[1]

print(numbers)

10. Why Doesn't This Swap Need a Temporary Variable?

In languages such as C or Java, beginners often learn:

temp = a
a = b
b = temp

Python can do this directly:

a = 10
b = 20

a, b = b, a

print(a)
print(b)

Output:

20
10

Python evaluates the values on the right side and then assigns them to the targets on the left.


11. What Is a List Comprehension?

An interviewer may first ask you to produce squares using a loop.

squares = []

for number in range(1, 6):
    squares.append(number * number)

print(squares)

Then they may ask for the Pythonic version:

squares = [number * number for number in range(1, 6)]

print(squares)

Output:

[1, 4, 9, 16, 25]

You can also add a condition:

even_squares = [
    number * number
    for number in range(1, 11)
    if number % 2 == 0
]

print(even_squares)

12. What Is the Difference Between Shallow Copy and Deep Copy?

This question is slightly more advanced, but freshers increasingly encounter it.

import copy

original = [[1, 2], [3, 4]]

shallow = copy.copy(original)
deep = copy.deepcopy(original)

original[0][0] = 100

print(original)
print(shallow)
print(deep)

A shallow copy creates a new outer container but may still refer to nested objects from the original.

A deep copy recursively creates independent copies of nested objects where possible.

This distinction becomes important when working with nested lists, configuration structures and complex objects.


13. Does Python Pass Arguments by Reference?

This question often produces confusing answers such as:

Python uses pass-by-reference.

That explanation is incomplete.

A better way to think about Python is that names are bound to objects, and function arguments receive references to those objects.

Consider:

def modify(items):
    items.append(4)

numbers = [1, 2, 3]

modify(numbers)

print(numbers)

Output:

[1, 2, 3, 4]

The function mutates the same list object.

Now consider:

def modify(number):
    number = 100

value = 10

modify(value)

print(value)

Output:

10

Inside the function, the local name number is rebound to another object. That does not rebind the caller's value variable.


14. Can Dictionary Keys Be Lists?

No.

This will fail:

data = {
    [1, 2]: "value"
}

Dictionary keys must be hashable. Because lists are mutable, they are not hashable and cannot normally be dictionary keys.

A tuple can often be used instead:

data = {
    (1, 2): "value"
}

print(data[(1, 2)])

Output:

value

15. What Is the Output of This Slicing Question?

text = "PYTHON"

print(text[::-1])

Output:

NOHTYP

The slice syntax is:

sequence[start:stop:step]

A step of -1 moves backward through the sequence, which is a common Python technique for reversing strings and lists.


What Interviewers Are Really Testing

The questions above may look simple, but they test several important Python concepts:

  • Mutable vs immutable objects
  • Object identity
  • References and assignment
  • Default function arguments
  • Truthiness
  • List operations
  • Slicing
  • Copy behavior
  • Functions and argument handling
  • Pythonic coding style

The best way to prepare is not simply to memorize the expected answer. Before reading the solution, run the code yourself and try to explain why Python produced that result.


Quick Python Interview Checklist for Freshers

Before attending your interview, make sure you are comfortable with:

  • Strings and string methods
  • Lists, tuples, sets and dictionaries
  • Mutable vs immutable types
  • Functions and arguments
  • *args and **kwargs
  • Loops and comprehensions
  • Exception handling
  • Classes and objects
  • Inheritance
  • Iterators and generators
  • Lambda functions
  • File handling
  • Modules and packages
  • Basic time and space complexity
  • Common coding problems

Continue Your Python Interview Preparation

Getting Python interview questions right requires both conceptual understanding and hands-on coding practice.

If you want to practice more interview questions, coding rounds and role-focused preparation, visit:

👉 InterviewPitch.com — Interview Questions, Coding Rounds & Interview Preparation

InterviewPitch provides curated interview preparation resources across Python, Java, JavaScript, React, SQL, system design and many other technical topics.

The goal is simple: understand the concepts, practice the code, and walk into your next interview knowing why an answer works rather than merely remembering it.


What Python question confused you during your first interview? Share it in the comments — it might help another developer preparing for the same question.

Top comments (0)