shouldn't 'string'.find('ugh') return 0, not -1 ?
jelleferinga at gmail.com
Wed Oct 31 16:32:49 CET 2007
Well, I this is another idiom in itself, right?
Your checking if something is part of an iterable.
I'm checking truth before entering a conditional expression.
The latter is considered to be pythonic, right?
On 10/31/07, Tim Chase <python.list at tim.thechases.com> wrote:
> > if I check a string for for a substring, and this substring isn't found,
> > should't the .find method return 0 rather than -1?
> > this breaks the
> > if check.find('something'):
> > do(somethingElse)
> > idiom, which is a bit of a pity I think.
> That idiom is spelled:
> if 'something' in check:
> Unless you really do need to start at a particular offset where
> you use the additional parameters of find(), such as
> find('something', 3, 42). In that case, you can slice your target:
> if 'something' in check[3:42]:
> The above is untested, so check for fencepost errors, but the
> theory holds.
> So pretty much, I'd never consider using find() :)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list