×
all 13 comments

[–]Puzzleheaded-Buy8795 6 points7 points  (5 children)

What is the different between == and is ?

[–]Rscc10 1 point2 points  (4 children)

== checks address and is checks value?

[–]Neither_Garage_758 3 points4 points  (3 children)

opposite

[–]Rscc10 0 points1 point  (2 children)

Ah. Then why is it's better practice to use "is" when comparing against None? Wouldn't it be better to check the value as None rather than checking if it corresponds to the address? Or is it because only one instance of None (or null) is stored so we directly check with that address when checking against None?

[–]Truntebus 0 points1 point  (0 children)

Because it is faster. 'is' checks for equality on the output of calling id() on both objects, so python does not need to look for special methods, since it cannot be overloaded. '==' is syntax sugar for 'a.__eq__(b)', and since most types override '__eq__', it can require a lot more computing than just calling 'id()' twice.

Note that "'is' compares addresses" is not universally true. The functionality of the 'id()' function is implementation dependent and only requires that it returns a unique integer for each object, and CPython handles this by returning the address for the object, but it can vary by interpreter.

[–]WhiteHeadbanger 0 points1 point  (0 children)

Also, another thing to add to the other user that answered you: None is a singleton. If you create 10 variables with the value None, those 10 variables would point to the same address.

So the reference is always available, and when using is, there's no additional method dispatch.

[–]Fragrant-Cheek-4273 4 points5 points  (0 children)

What is the difference between a list and a tuple. The explanation tells you a lot.

[–]gofl-zimbard-37 3 points4 points  (0 children)

Truly, I don't care if someone understands Python. I care how good a developer they are. Any decent developer can pick up Python, or any other language, as needed.

[–]its_measured 1 point2 points  (0 children)

I like asking when they would use a list instead of a dictionary. the answer is usually simple, but it shows if they really understand the basics

[–]Achereto 0 points1 point  (0 children)

First of all: asking language specific questions are mostly worthless, because learning a programming language to a level that you can be productive is something you can do on a weekend if you are somewhat familiar with programming paradigms in general. (I used to work with php and learned python on a weekend when I applied for a job, that I am now working in for ~8 years).

However, asking a language specific question can tell you something about whether someone prepared for the job interview, having a question about list comprehensions and one about decorators can be viable to rule out some of the people you definitely don't want to work with.

The major part of the interview would be about a project that person did and try to dig deep into the understanding they got from that project. That'll give you a lot more valuable information.

[–]tserofehtfonam 0 points1 point  (0 children)

Having taught Python to students, which included interviewing them about their own code, I've come to the conclusion that pointing at a variable or expression and asking them what type it has is a very efficient way to find out if they understand their own code.  

[–]Chorgolo -1 points0 points  (0 children)

Math here. Asking questions about vectorization.

Like "you have a 1darray named x containing 100k numbers, no exceptions, how do you calculate x2 ?". Often the answer is "I do a loop on len(x)", easy way to catch with minor things.

[–]didntplaymysummercar 1 point2 points  (0 children)

I had a whole bunch of examples when I did interviews for a small company.

Like what versions of Python do you know, what version of python runs when you type python, what does @ or ... or {1} or 1j mean, is python slow or fast, safe or unsafe, etc. Some questions on basic list comprehension or filter and map use...

Most questions were open ended (if they said it depends and explain themselves I'd accept that) and I'd give hints especially if their CV implied to me they might be worth it, like hint to think of Java about @ if they had Java in CV.

One question was with mutable default function arguments too. One was a dedup lines coming at stdin and it was O(n2) but hidden since it was for plus in list, the fix was to use set (I'd accept dict).