Jupyter and Python basics interview questions
25 questions interviewers ask on getting started, from first principles to the follow-ups. The first 3 model answers are free to read; Pro opens the rest.
Python and notebooks
- Is Python compiled or interpreted?●
Interpreted, in the usual sense. CPython, the standard implementation, compiles source code to bytecode and then its interpreter executes that bytecode one instruction at a time. There is no separate compile step for the programmer to run.
- What is the difference between Python 2 and Python 3 that you are most likely to notice?●
printis a function in Python 3:print("hello"). Python 2'sprint "hello"givesSyntaxError: Missing parentheses in call to 'print'. Python 2 reached end of life in 2020, so new code is Python 3. - What is the difference between a statement and an expression?●
A statement is one instruction, such as the assignment
total = 2.25 + 1.25. An expression is any piece of code that evaluates to a value, such as2.25 + 1.25on the right of it. An expression can stand alone as a statement, which is why a notebook cell whose last line is2.25 + 1.25 + 3.50displays7.0; an assignment has no value, so a cell ending in one displays nothing. - In a Jupyter notebook, why can a cell that worked earlier fail after a restart, and what do you do about it?●●
Variables and types
- Is Python statically or dynamically typed? Is it strongly or weakly typed?●
- What actually happens in
x = 5?●● - What is the difference between
isand==?●● - Are integers mutable? What does
x += 1do to the object?●● - How do you swap two variables in Python?●
- What is
None, and how do you check for it?● - Can you name a variable
list? Should you?●● - What are type annotations, and does Python enforce them?●●
Conversion and truthiness
- What does
input()return?● - Which values are falsy in Python?●●
- What is the difference between
int(2.9)andround(2.9)?●● - Why is
"10" > "9"False?●●
Operators
- What is the difference between
/and//?● - What is
-7 // 2, and-7 % 2? Why?●● - What do
2 ** 3 ** 2and-2 ** 2evaluate to?●● - Why is
0.1 + 0.2 == 0.3False, and how should you compare floats?●● - What do
andandorreturn?●● - What is
True + True?●●
Formatting
- What does
printreturn? What do itssepandendarguments do?● - How do you print a number with two decimal places and a thousands separator?●
- What does
f"{x=}"do?●●