My limited brain cannot understand why this happens:
>>> print '' in 'lolsome'
True
In PHP, a equivalent comparison returns false (and a warning):
var_dump(strpos('lolsome', ''));
pythonpython-internalsstring
My limited brain cannot understand why this happens:
>>> print '' in 'lolsome'
True
In PHP, a equivalent comparison returns false (and a warning):
var_dump(strpos('lolsome', ''));
Best Answer
From the documentation:
From looking at your
print
call, you're using 2.x.To go deeper, look at the bytecode:
COMPARE_OP
is where we are doing our boolean operation and looking at the source code forin
reveals where the comparison happens:and where cmp_outcome is in the same file, it's easy to find our next clue:
which is in abstract.c:
and to come up for air from the source, we find this next function in the documentation:
and further down in the same documentation:
Where
''
isn'tnull
, the sequence'lolsome'
can be thought to contain it.