[Tutor] Is "var = None" in Python equivalent to "Set var

wesley chun wescpy at gmail.com
Mon Jun 30 06:53:31 CEST 2008


> As I understand it there are no cases where obj==None and obj is None
>  will give different results (which is not true for == vs is in
>  general), so is there any practical difference?  Maybe you save a
>  handful of cycles?


as far as i know, that's it. but if this comparison happens a *lot* in
your code, it starts to add up.  for the newbies, just remember that
"==" is an object *value* comparison vs. 'is' which is an object
*identity* comparison.

the former requires pulling out the values of both objects and doing a
comparison while the latter is just checking the references to see if
both are looking at exactly the same object (IDs match) so there's no
need to fetch their values.

-wesley

ps. danny's example is pretty scary tho...


More information about the Tutor mailing list