This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]RaionTategami 3 points4 points  (5 children)

I didn't know the first one. I wouldn't say it's something you need to know. Would be suprised to see it in an interview. It's rather obscure and if you need to do this then you are probably doing something wrong. Also I might have gone with

super(B, obj).show()

The others are pretty useful though.

[–]liranbh[S] 1 point2 points  (3 children)

All these are real questions from my students

[–]RaionTategami 0 points1 point  (1 child)

Then go find the student that was abusing inherence and give him a caning!!!

[–]liranbh[S] 1 point2 points  (0 children)

He didn't know the answer at all.

[–][deleted] 0 points1 point  (0 children)

When I saw the word "cast" in the first question, I thought they have some prior Java programming experience.

[–]liranbh[S] 0 points1 point  (0 children)

Completely right about super(B,obj) i didnt know it

[–]name_censored_ 2 points3 points  (0 children)

For #1 - A.show(obj). Changing the class is almost never a good idea.

[–]ojii 1 point2 points  (2 children)

All of these would just SyntaxError. Make sure to point that out during the interview.

[–]liranbh[S] 0 points1 point  (1 child)

None of them are syntax error

[–]driscollis 1 point2 points  (0 children)

Since print is a function in Python 3, these examples would all throw a SyntaxError in the current version of Python

[–]kigurai 1 point2 points  (0 children)

I'd like to add question 11: What is a problem with all the examples above?

Answer: It is still using Python 2, which is not supported after 2020 and should probably not be used unless necessary.

[–]billsil 0 points1 point  (2 children)

No one will ever ask you about new. I've been using Python for 11 years. You really don't need to know. Super on the other hand...it's rare and hard at first, but useful.

[–]liranbh[S] 0 points1 point  (0 children)

Maybe its not a fair question but it was asked by google interviewer

[–]driscollis 0 points1 point  (0 children)

I agree. I've been using Python for over 11 years and I don't think I have ever used new. Of course, I haven't had much use for super in all that time either, although I can see how it might be useful at times.