testing for valid reference: obj vs. None!=obs vs. obj is not None
Sandra-24
sandravandale at yahoo.com
Mon Sep 4 22:24:18 EDT 2006
alf wrote:
> Hi,
>
> I have a reference to certain objects. What is the most pythonic way to
> test for valid reference:
>
> if obj:
>
> if None!=obs:
>
> if obj is not None:
I like this way the most. I used timeit to benchmark this against the
first one, expecting it to be faster (the first is a general false
test, the last should just be comparing pointers) but it's slower.
Still I don't expect that to ever matter, so I use it wherever I wish
to test for None, it reads the best of all of them.
-Sandra
More information about the Python-list
mailing list