Skip to content
Laviyx Learn

Try

Python course menu

Beginner Python Interview Questions and Answers

Common Python interview questions for freshers with clear answers and runnable examples: lists vs tuples, == vs is, mutability, division operators, truthy values, slicing, dictionaries, and more.

Beginner5 min readUpdated
On this page

These questions come up in nearly every entry-level Python interview. For each one, try answering out loud first, then open the solution. Interviewers value a clear explanation with a tiny example more than a memorised definition.

Concepts#

1. What are Python's key features?#

Show solution
  • Readable syntax, using indentation instead of braces.
  • Interpreted: code runs line by line without a separate compile step.
  • Dynamically typed: variables do not declare types; values do.
  • Batteries included: a large standard library (files, JSON, dates, HTTP, testing…).
  • Multi-paradigm: procedural, object-oriented and functional styles all work.
  • A huge ecosystem of third-party packages on PyPI.

2. What is the difference between a list and a tuple?#

Show solution

A list is mutable (can change); a tuple is immutable:

Python
a = [1, 2, 3]
t = (1, 2, 3)
a[0] = 99
print(a)

try:
    t[0] = 99
except TypeError as e:
    print("TypeError:", e)
Output
[99, 2, 3]
TypeError: 'tuple' object does not support item assignment

Use tuples for fixed records and dictionary keys; lists for collections that change. See Tuples.

3. What is the difference between == and is?#

Show solution

== compares values; is checks whether two names refer to the same object:

Python
x = [1, 2]
y = [1, 2]
print(x == y, x is y)
Output
True False

Use is only for None (if value is None:).

4. What are mutable and immutable types?#

Show solution
  • Immutable (cannot change after creation): int, float, str, tuple, bool, frozenset.
  • Mutable: list, dict, set, and most user-defined objects.

It matters because functions can modify mutable arguments:

Python
def f(x):
    x.append(4)

lst = [1, 2, 3]
f(lst)
print(lst)
Output
[1, 2, 3, 4]

5. What do /, // and % do?#

Show solution
Python
print(7 / 2, 7 // 2, 7 % 2, -7 // 2)
Output
3.5 3 1 -4

/ is true division (always a float), // is floor division (rounds down, so -7 // 2 is -4), and % is the remainder. See Operators.

6. Which values are falsy in Python?#

Show solution

False, None, zero (0, 0.0), and empty collections ("", [], (), {}, set()). Everything else is truthy, including the string "0":

Python
print(bool(""), bool("0"), bool([]), bool(0.0), bool(None))
Output
False True False False False

7. Why is 0.1 + 0.2 not equal to 0.3?#

Show solution

Floats are stored in binary, which cannot represent 0.1 exactly, so tiny rounding errors appear:

Python
print(0.1 + 0.2 == 0.3, round(0.1 + 0.2, 2) == 0.3)
Output
False True

Compare floats with a tolerance (math.isclose) or round them, and use the decimal module for money.

Short coding questions#

8. Reverse a string.#

Show solution
Python
s = "Python"
print(s[::-1], s[1:4], s[-2:])
Output
nohtyP yth on

[::-1] steps backwards through the whole string. Be ready to explain slicing: [start:stop:step], with stop excluded. See Strings.

9. Swap two variables without a temporary variable.#

Show solution
Python
a, b = 5, 10
a, b = b, a
print(a, b)
Output
10 5

The right side builds a tuple (10, 5), which is then unpacked into a and b.

10. Remove duplicates from a list.#

Show hint

A set removes duplicates but has no order. If the original order matters, use a dictionary.

Show solution
Python
nums = [3, 1, 3, 2, 1]
print(sorted(set(nums)), list(dict.fromkeys(nums)))
Output
[1, 2, 3] [3, 1, 2]

set() loses the order (so sort if you need a predictable result); dict.fromkeys() keeps the first occurrence of each value in its original order.

11. Read a dictionary key that might not exist.#

Show solution
Python
d = {"a": 1}
print(d.get("b"), d.get("b", 0))
Output
None 0

d["b"] would raise KeyError; get() returns None or a default. See Dictionaries.

Tips for beginner interviews#

  • Talk through your thinking: "first I'll handle the empty case, then…".
  • Use Pythonic tools (enumerate, zip, comprehensions, get), but also be able to write the loop by hand.
  • Mention edge cases: empty input, duplicates, negative numbers, None.

Continue with Intermediate Questions.

Finished this lesson?