GoCode logoGoCode
← Back to blog

Top 20 Python Interview Questions for Freshers (with Answers)

GoCode Team25 June 20263 min read

Python is the most common language freshers name on their resumes — which means interviewers have a well-worn set of questions to test whether that line is real. Here are twenty that come up constantly, with answers short enough to actually say in an interview.

Core language

  1. List vs tuple? Lists are mutable, tuples are immutable. Tuples can be dict keys and are slightly faster; use them for fixed collections.
  2. What is a dictionary? A hash-map of key–value pairs with average O(1) lookup. Keys must be hashable.
  3. How is memory managed? Reference counting plus a cycle-detecting garbage collector, all managed by the Python runtime.
  4. What is the GIL? The Global Interpreter Lock lets only one thread execute Python bytecode at a time — so threads help I/O-bound work, while CPU-bound work needs multiprocessing.
  5. is vs ==? == compares values; is compares identity (same object in memory).
  6. Shallow vs deep copy? Shallow copies the outer container but shares nested objects; deep copy duplicates everything recursively.
  7. What are *args and **kwargs? They collect extra positional and keyword arguments so a function can accept a variable number of inputs.
  8. Mutable default argument trap? Defaults are evaluated once at definition; a default list persists across calls. Use None and create the list inside.

Functions and OOP

  1. What is a lambda? An anonymous single-expression function, typically used as a key function for sorted, min or max.
  2. What is a decorator? A function that takes a function and returns an enhanced version — used for logging, timing, authentication.
  3. What is a generator? A function with yield that produces values lazily, saving memory on large sequences.
  4. List comprehension? A concise way to build lists: [x*x for x in nums if x > 0] — say it reads as "collect x squared for every positive x".
  5. @staticmethod vs @classmethod? Static methods get no implicit first argument; class methods receive the class itself and are commonly used as alternative constructors.
  6. How does inheritance work? A class can extend one or more parents; method lookup follows the Method Resolution Order (MRO).
  7. What are dunder methods? Double-underscore hooks like __init__, __str__, __len__ that let your objects work with built-in syntax.

Practical

  1. How do you handle exceptions? try/except/else/finally; catch specific exceptions, never a bare except.
  2. How do you read a file safely? with open(path) as f: — the context manager closes it even on errors.
  3. What is a virtual environment? An isolated interpreter + packages per project, so dependencies don't clash system-wide.
  4. How would you remove duplicates while keeping order? list(dict.fromkeys(items)) — dicts preserve insertion order.
  5. How do you reverse a string? Slicing: s[::-1]. Be ready to also do it with a loop if asked.
Interview tip: for every answer here, be ready with a two-line code example. "Can you show me?" is the standard follow-up — and where prepared candidates separate themselves.

Practice writing these in a real editor with instant feedback rather than reading them the night before — recall under pressure is what the interview actually tests.

Want to try GoCode?

Get started