Job preparationPython
Python interview questions and answers

From data types to decorators, generators and pandas — the questions asked most often for Python roles.
Python is wanted in three places at once now — web, data science and AI. The good news is that the interview questions stay much the same across all three.
The questions below run from the very basics of the language out to pandas. Under each one is exactly what your answer should cover.
The questions
What is Python and what are its main characteristics?
What to coverSimple, readable syntax; dynamic typing and dynamic binding; high-level data structures; a large standard library; and it is interpreted and interactive.
How is memory managed in Python?
What to coverCover garbage collection, reference counting, and the private heap with its pooled allocator.
What data types does Python have and what are they used for?
What to coverInteger, float, string, list, tuple, dictionary and set — and be ready to say what separates them.
What is the difference between a list and a tuple?
What to coverA list is mutable: its items can be changed, added to or removed, and it is written with [] brackets. A tuple is immutable: once set, its items cannot be changed, and it is written with () brackets.
What is a decorator in Python and how does it work?
What to coverA decorator is a way of changing what a function does: it takes another function as its argument and returns a new function.
How are exceptions handled in Python?
What to coverThrough try, except, else and finally blocks.
What is the difference between a generator and an iterator in Python?
What to coverTalk about the yield keyword, and the __iter__() and __next__() methods.
How do you work with files in Python?
What to coverOpening, reading, writing and closing a file — and the with context manager.
What is a lambda function in Python and when is it used?
What to coverFor creating short, throwaway functions where a full def would be too much.
What are modules and packages in Python, and how are they imported?
What to coverThe difference between a module and a package, and the import, from and as keywords.
What are the pandas and NumPy libraries, and how do they differ?
What to coverpandas is for data manipulation; NumPy is for scientific computing on arrays.
Tips for this round
- Keep a two-line example in your head for each concept — boards often say "show me".
- On questions like list versus tuple, do not stop at the definition; say when you would use each.
- Decorators and generators are where most candidates stall. Give those extra time.