r/learnpython • u/Recent-Analysis-6880 • 43m ago
Is it normal in an interview for an interviewer to ask very niche questions?
I recently had an interview for an intern position. my resume had some good Python projects and my previous internship experience also involved Python.
The interviewer began by asking me basic Python questions, which I answered well. He then moved on to more detailed questions.
Interviewer: What would be the output of the following code?
num1 = 1
num2 = 1
num3 = 257
num4 = 257
print(num1 is num2, num3 is num4)
I know about integer caching in python, so I said True, False. The interviewer asked if I was sure, and I said yes. He then handed me his laptop, opened VS Code, and asked me to run the code. To my horror, it printed True, True.
He moved on to the next question.
Interviewer: What is __init__ in Python?
Me: It’s a constructor for a class.
Interviewer: What is the first argument it takes?
Me: The object we created.
Interviewer: If it’s the constructor, how can it take the object itself? Who creates the object if __init__ is the constructor?
Me : Silence.
I know it's kinda my fault for this question.
Moved on to the next question
Interviewer: What is the output of the following code?
def fun(a=[], i=1):
a.append(i)
print(a)
fun()
fun(i=2)
I didn’t know that Python reuses the same list when it’s used as a default argument, so I got it wrong.
He moved on to the next question.
Interviewer: What is the output of this code?
tup = ([1, 2, 3], 4, 5)
try:
tup[0] += [4, 5]
print('tup modified', tup)
except:
print('Not modified', tup)
Apparently it raises an error on the third line, but the list still gets modified. The output is:
Not modified ([1, 2, 3, 4, 5], 4, 5)
I haven’t heard back yet, but I’m wondering: is this how python specific interviews typically go?
How should I prepare for these kinds of scenarios next time?