I've put together a series of posts with my personal database of Python interview questions. It's not perfect, it's not complete, and no, there aren't any answers included. Some of the questions might even feel a little odd or out there. But in my experience, they're great at helping you figure out who's really ready for the job.
The series is split into three parts based on experience level:
- Python Interview Questions: Part I (Junior)
- Python Interview Questions: Part II (Middle)
- Python Interview Questions: Part III (Senior)
Got a question you think should be here? Or something you always ask in interviews? Let me know — I'd love to hear your thoughts!
Questions
1. Python Basics
Q: What is Python?
Q: What is the lambda function in Python? Why does it exist in Python?
Q: What is pass
in Python?
Q: What is *args
, **kwargs
in function definition?
Q: What is docstring in Python? How to write them? Are they required?
Q: What keywords can be used in conjunction with the for
keyword?
Q: What is slicing in Python? Can slices have negative indices?
Q: What is the __init__.py
module? What it's for?
Q: What is PEP8?
2. Data Types and Structures
Q: What are the built-in data types that Python provides? Which of them are mutable, which are immutable?
Q: What is the difference between list and tuple types in Python?
Q: What could be the key in dict
?
Q: What's the difference between globals()
, locals()
, and vars()
?
Q: What are data classes in Python? When should you use them?
3. Object-Oriented Programming (OOP)
Q: What is @classmethod
, @staticmethod
, @property
?
Q: What is the difference between @classmethod
and @staticmethod
?
Q: Does Python fully support object-oriented programming? Why or why not?
Q: What the self
is used for in Python?
Q: What is the __init__
method used for?
Q: How do I view object methods?
Q: What is the __dict__
attribute of an object in Python?
4. Python Modules and Packages
Q: What is the difference between a module and a package?
Q: Explain how to make a Python script executable on Unix?
5. Advanced Python Concepts
Q: Can you write multithreading applications in Python? What's the difference between multithreading and multiprocessing?
Q: What is a decorator? How to create a custom decorator?
Q: Explain pickling and unpickling in Python. How does it differ from marshaling and unmarshaling?
Q: How do you retrieve documentation on an object or method in Python?
6. Coding Challenges
Q: What's the most Pythonic way of swapping values of variables?
Q: Write a function that produces the Fibonacci sequence.
Q: How to translate a string containing a binary code (1 and 0) into a number (integer)? Write a function to do this.
Q: How to check that tuple A contains all elements of tuple B. Do both tuples contain unique values? Write a function to do this.
Q: What is the output of the following code?
def f():
x = 15
print(x)
x = 12
f()
Q: How to convert a string to a number that consists of letters ASCII code. Example: 'abcd' -> 979899100. Write a function to do this.
Q: How to remove empty lines from a list of lines (with a length of 0). Write a function to do this.
Q: Write a function that counts all distinct pairs with a difference equal to k
.
Q: Write a function that returns a string of numbers from 0 to 100, "0123456789101112...".
Q: Write a function that makes a list with unique items from a list with duplicate items. Example: [1, 1, 2, 3, 3]
-> [1, 2, 3]
.
Q: Make a list of prime numbers from the range (1, 100)
using Python.
Q: Write a program that prints the numbers from 1 to 20. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers that are multiples of both three and five print "FizzBuzz".
Think something's missing? Got a killer Python question of your own? Share it in the comments, or tweet it my way — I'd love to hear from you!
Additional materials
- Fluent Python by Luciano Ramalho
- Effective Python by Brett Slatkin
- Python Crash Course by Eric Matthes