Top 20 Python interview questions in 2026 (with sample answers)
These are the questions you'll be asked at almost every Python interview from junior to mid-level. Pomiń pytanie „Co to jest Python?” softballs other sites pad with — these are the ones that separate hires from passes.
Podstawy języka
1. Mutable vs immutable types — name 3 of each.
Zmienne: lista, dykt, zestaw, bajtarray.
Immutable: int, float, str, tuple, frozenset, bytes.
Why it matters: immutables are hashable (can be dict keys / set members); mutable nie są. Default arguments must NEVER be mutable (def f(x=[]): is the classic bug).
2. What's the difference between is and ==?
== porównuje wartości. is compares identity (same object in memory).
Use is only for sentinels — None, True, False. Gdziekolwiek indziej użyj ==. (x is 0 works in CPython for small ints due to interning, but you're relying on an implementation detail.)
3. Wyjaśnij GIL w jednym zdaniu.
Globalna blokada interpretera pozwala tylko jednemu wątkowi Pythona na wykonanie kodu bajtowego na raz, więc wątki przyspieszają kod związany z we/wy, ale NIE kod związany z procesorem. For CPU-bound parallelism use multiprocessing, or the new free-threading mode (PEP 703) coming in 3.13+.
4. List comprehension vs generator expression — when each?
List comp [x*x for x in range(n)] builds the full list in memory. Generator expression (x*x for x in range(n)) is lazy — produces one item at a time. Użyj generatorów, gdy:
- lista byłaby ogromna lub nieskończona
- wystarczy powtórzyć raz
- you can short-circuit (any/all/next/first match)
5. What does *args, **kwargs actually mean?
*args collects positional arguments into a tuple. **kwargs collects keyword arguments into a dict. Use for forwarding to inner functions (forward(*args, **kwargs)) or for variadic APIs.
Struktury danych
6. What's the time complexity of dict lookup, list lookup, and in for each?
d[k]: O(1) average, O(n) worst-case (rare with good hash distribution)lst[i]: O(1) według indeksuk in d: średnia O(1).x in lst: O(n) — typowy problem
If you do many in checks against a collection, convert to set/dict first.
7. zestaw czy zamrożony zestaw — kiedy każdy?
set można modyfikować, nie może być klawiszem dyktowania. frozenset jest niezmienny i podlega haszowaniu. Use frozenset when you need a set as a dict key or set member.
8. How would you remove duplicates while preserving order?
Pythonic since 3.7 (dict preserves insertion order):
The set trick list(set(items)) is faster but loses order.
Funkcje i OOP
9. Co to jest zamknięcie? Podaj przykład, w którym byś go użył.
A function that captures variables from its enclosing scope. Used for stateful factories, decorators, and callbacks:
10. Explain @staticmethod, @classmethod, and instance method differences.
- Instance method: takes
self, has access to instance state. @classmethod: takescls(the class), used for alternate constructors (User.from_dict(...)) or working with class-level state.@staticmethod: takes neither, just a function namespaced under the class.
11. Dziedziczenie wielokrotne – czym jest MRO?
Method Resolution Order — the deterministic order Python walks when looking up a method on an instance. Python uses C3 linearization: left-to-right, depth-first, with diamond resolution. Sprawdź Class.__mro__.
Multiple inheritance works fine when every class plays nicely with super().
12. @dataclass — what does it give you for free?
__init__, __repr__, __eq__ based on declared fields. With frozen=True it also makes the class hashable. field(default_factory=list) for mutable defaults — never use [] as a default.
Typowe pułapki
13. Co w tym złego?
The default [] is created once at function definition and shared across all calls. add("a"); add("b") zwraca ["a", "b"]. Fix: def add(item, items=None): then if items is None: items = [].
14. Kopia płytka czy głęboka?
b = a.copy() (or list(a)) creates a new list pointing at the SAME inner objects. For nested structures, mutating inner objects affects both. Aby kopiować rekurencyjnie, użyj copy.deepcopy(a).
15. When does break exit only the inner loop?
Zawsze. break exits the nearest enclosing for/while. To exit multiple loops, factor into a function and use return, or use an explicit flag.
Asynchronizacja/współbieżność
16. asynchronizować/czekać na jednym oddechu?
async def definiuje współprogram. await suspends until the awaited coroutine resolves, yielding control to the event loop. asyncio.run(main()) is the top-level entry point. Coroutines don't run when called — they return a coroutine object that must be awaited or scheduled.
17. Why is time.sleep(1) dangerous inside an async function?
It blocks the entire thread, including every other coroutine on the event loop. Zamiast tego użyj await asyncio.sleep(1).
18. asyncio vs threading vs multiprocessing — when which?
- asyncio — I/O-bound, single-threaded, lightweight (1000s of concurrent tasks). Serwery HTTP, skrobanie sieci.
- threading — I/O-bound where the library is sync-only. Obsługiwane przez wątki systemu operacyjnego, ograniczone przez GIL.
- wielprocesorowość — związana z procesorem. Separate processes, no GIL constraint, but data is pickled across boundaries.
Idiomy w języku Python
19. The cleanest way to merge two dicts in 2026?
d2 wygrywa w konfliktach. For "create a new dict with d2's values overriding d1":
{**d1, **d2} działa również w wersji 3.5+.### 20. wyliczyć vs zakres(dł(...))?
Pythoniczny:
Antywzorzec:
enumerate jest szybsze, jaśniejsze i idiomatyczne.
Jak skutecznie się przygotować
Nie zapamiętuj. Poćwicz pisanie odpowiedzi na GŁOŚNO, jak do człowieka. Nagraj siebie, jeśli jesteś sam. Największą pułapką prawdziwych rozmów kwalifikacyjnych jest zamrożenie, a nie brak wiedzy.
Jeśli potrzebujesz uporządkowanego ćwiczenia na temat tych wzorców plus strony algorytmicznej, nasza ścieżka przygotowania do rozmowy kwalifikacyjnej zawiera 100 lekcji obejmujących dokładnie ten temat — od podstaw Big-O, poprzez historie behawioralne STAR i pełne uwieńczenie próbnej prezentacji na miejscu. Pierwsze 15 lekcji gratis, bez karty.