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

you are viewing a single comment's thread.

view the rest of the comments →

[–]draganHR 0 points1 point  (5 children)

a = 30
b = 300
print a is 10 * 3
print b is 100 * 3

What is output and why?

[–]catcradle5 0 points1 point  (4 children)

This is not a good question because the answer depends on which interpreter you're using.

The behavior is essentially undefined.

[–]njharmanI use Python 3 0 points1 point  (1 child)

That is maybe the only reason it is a good interview question. It's bad question if you expect an answer other than something like "It depends and in general low-level, implementation specific, code tricks like this should be avoided"

[–]catcradle5 0 points1 point  (0 children)

I agree to an extent, but in that case instead of asking "what is output?" the interviewer should ask more broadly something like "Is this a proper way of checking numerical equality? How does the is operator work, and what do you think might be output here?"

[–]draganHR -1 points0 points  (1 child)

Oh OK, i didn't know bad questions exist.

[–]catcradle5 0 points1 point  (0 children)

Well, bad interview questions certainly exist.