Tech

Python

Python is one of the most versatile and widely-used programming languages in the world. Known for its clean syntax and readability, it powers everything from web backends and data science pipelines to automation scripts and AI models. Interviewers test Python candidates on core language mechanics like the GIL, decorators, generators, and memory management — expect a mix of conceptual questions and practical problem-solving.

What you get

Questions

20

Difficulty

3 levels

Answer Formats

2

Use the toggle on each card to move between an interview-ready answer and a simpler explanation. Questions are sorted from beginner to advanced, and the keywords are highlighted. You can also blur the answers to practice recalling them from memory.

Questions

Practice the answers out loud.

All topics

Question 1

What is Python and what are its key features?

Beginner

How to answer in an interview

Python is a high-level, interpreted, dynamically-typed programming language known for its readability and simple syntax. Key features include automatic memory management, a huge standard library, support for multiple paradigms (procedural, object-oriented, functional), and cross-platform portability. It's widely used in web development, data science, automation, and AI.

Question 2

What is the difference between a list and a tuple in Python?

Beginner

How to answer in an interview

A list is mutable, meaning its elements can be changed, added, or removed after creation, and it's defined with square brackets. A tuple is immutable — once created, its contents cannot change — and is defined with parentheses. Tuples are generally faster and used for fixed collections of data, while lists suit data that changes over time.

Question 3

What are *args and **kwargs used for?

Beginner

How to answer in an interview

*args allows a function to accept any number of positional arguments, collecting them into a tuple, while **kwargs allows any number of keyword arguments, collecting them into a dictionary. They're useful when you don't know in advance how many arguments will be passed, such as in wrapper functions or flexible APIs.

Question 4

Explain list comprehension in Python.

Beginner

How to answer in an interview

List comprehension is a concise way to create lists using a single line of code, combining a for loop and optional conditional logic, e.g. [x*2 for x in range(10) if x % 2 == 0]. It's generally faster and more readable than an equivalent for loop with append calls.

Question 5

What is the difference between '==' and 'is' in Python?

Beginner

How to answer in an interview

'==' checks value equality, meaning whether two objects have the same content, while 'is' checks identity, meaning whether two references point to the exact same object in memory. Two different objects can have equal values but not be identical, so 'is' should generally only be used for singleton comparisons like None.

Question 6

What are Python's built-in data types?

Beginner

How to answer in an interview

Python's core built-in data types include numeric types like int, float, and complex; sequence types like str, list, and tuple; mapping type dict; set types set and frozenset; and the boolean type bool. Each has different mutability and use-case characteristics, for example lists are mutable ordered sequences while tuples are immutable.

Question 7

How does exception handling work in Python?

Beginner

How to answer in an interview

Python uses try/except blocks to catch and handle exceptions, an optional else block that runs if no exception occurs, and a finally block that always executes regardless of whether an exception was raised, typically used for cleanup. You can raise custom exceptions using the 'raise' keyword and create custom exception classes by subclassing Exception.

Question 8

What is a lambda function?

Beginner

How to answer in an interview

A lambda function is a small, anonymous, one-line function defined using the 'lambda' keyword without a formal name, typically used for short operations passed to functions like map(), filter(), or sorted(). Unlike regular functions defined with 'def', lambdas are limited to a single expression.

Question 9

What are Python decorators?

Intermediate

How to answer in an interview

A decorator is a function that takes another function as input and extends or modifies its behavior without changing its source code. They're applied using the '@' syntax above a function definition and are commonly used for logging, access control, timing, and caching. Internally, a decorator returns a wrapper function that calls the original function plus extra logic.

Question 10

What is a generator in Python?

Intermediate

How to answer in an interview

A generator is a special type of function that uses the 'yield' keyword to produce a sequence of values lazily, one at a time, instead of returning them all at once. This makes generators memory-efficient for working with large or infinite data sets since values are computed on demand. Generators automatically implement the iterator protocol.

Question 11

What is the difference between deep copy and shallow copy?

Intermediate

How to answer in an interview

A shallow copy creates a new object but copies references to the nested objects inside it, so changes to nested mutable objects affect both copies. A deep copy recursively copies every nested object, creating a fully independent clone. Python's 'copy' module provides copy() for shallow copies and deepcopy() for deep copies.

Question 12

Explain mutable vs immutable objects in Python.

Intermediate

How to answer in an interview

Mutable objects, such as lists, dictionaries, and sets, can be changed after creation without changing their identity. Immutable objects, such as strings, integers, and tuples, cannot be altered in place — any 'change' actually creates a new object. This distinction matters for function arguments, hashing, and avoiding unintended side effects.

Question 13

How does a Python dictionary work internally?

Intermediate

How to answer in an interview

A Python dictionary is implemented as a hash table where each key is hashed to determine its storage bucket, giving average O(1) time complexity for lookups, insertions, and deletions. Collisions are handled internally through open addressing. Since Python 3.7, dictionaries also preserve insertion order as an implementation detail made official.

Question 14

What is duck typing in Python?

Intermediate

How to answer in an interview

Duck typing is a concept where an object's suitability for use is determined by the presence of certain methods or attributes rather than its explicit type — 'if it walks like a duck and quacks like a duck, it's a duck.' This allows Python to support polymorphism without requiring formal interfaces or inheritance.

Question 15

What is the difference between @staticmethod and @classmethod?

Intermediate

How to answer in an interview

A @staticmethod doesn't receive an implicit first argument and behaves like a plain function placed inside a class for organizational purposes. A @classmethod receives the class itself as its first argument, conventionally named 'cls', allowing it to access or modify class-level state and is often used for alternative constructors.

Question 16

What are context managers and the 'with' statement used for?

Intermediate

How to answer in an interview

A context manager manages the setup and teardown of resources, such as opening and closing a file, using the __enter__ and __exit__ methods. The 'with' statement ensures that cleanup code always runs, even if an exception occurs, making resource management safer and more concise than manual try/finally blocks.

Question 17

Explain the Global Interpreter Lock (GIL) in Python.

Advanced

How to answer in an interview

The GIL is a mutex in CPython that allows only one thread to execute Python bytecode at a time, even on multi-core machines. This means CPU-bound multi-threaded programs don't get true parallelism, though I/O-bound programs still benefit from threading since the GIL is released during I/O waits. To achieve real parallel CPU work, developers typically use the multiprocessing module instead of threading.

Question 18

What is monkey patching in Python?

Advanced

How to answer in an interview

Monkey patching refers to dynamically modifying or extending a class or module at runtime, such as replacing a method on an existing object without altering its original source code. It's often used in testing to mock dependencies but can make code harder to understand and maintain if overused.

Question 19

How does Python manage memory and garbage collection?

Advanced

How to answer in an interview

Python primarily uses reference counting, where each object tracks how many references point to it, and is deallocated once that count hits zero. To handle reference cycles that reference counting alone can't clean up, Python's garbage collector periodically runs a cyclic garbage collection algorithm to detect and free unreachable cyclic structures.

Question 20

What are metaclasses in Python?

Advanced

How to answer in an interview

A metaclass is the 'class of a class' — it defines how classes themselves behave and are constructed, with 'type' being the default metaclass in Python. Metaclasses allow developers to customize class creation, such as automatically registering subclasses or enforcing coding standards, by overriding methods like __new__ or __init__ on the metaclass.

More in Tech

Keep browsing related topics.

Browse all