Re: shouldn't 'string'.find('ugh') return 0, not -1 ?




the subject pretty much says it all.
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?

I belive str.find should return the first position where the substring appears.
If "string".find("ugh") were to return 0, how would you differentiate from
"ugh".find("ugh")? That one *should* return 0.


this breaks the

if check.find('something'):
do(somethingElse)

idiom, which is a bit of a pity I think.

It breaks the idiom because you are speaking the wrong language.

You should be doing:

if "something" in "string":
do(something())

wich is clearer IMHO.

cheers,

-jelle

See ya,

--
Luis Zarrabeitia
Facultad de Matemática y Computación, UH
http://profesores.matcom.uh.cu/~kyrie




--
http://mail.python.org/mailman/listinfo/python-list


--
"Al mundo nuevo corresponde la Universidad nueva"
UNIVERSIDAD DE LA HABANA
280 aniversario
.



Relevant Pages

  • shouldnt string.find(ugh) return 0, not -1 ?
    ... if I check a string for for a substring, and this substring isn't found, ... idiom, which is a bit of a pity I think. ...
    (comp.lang.python)
  • Re: [QUIZ] Longest Repeated Substring (#153)
    ... My hack at the substring problem is based on suffix ... in the original string. ... def initialize ...
    (comp.lang.ruby)
  • Favicon type detection - possible?
    ... this is my cobbled together browser detection ... {string: navigator.userAgent, ... subString: "OmniWeb", ... {// for newer Netscapes ...
    (comp.lang.javascript)
  • Comments on Comments (was Re: Getting to 100 (#119))
    ... # yield each partitioning of the receiver into count partitions ... # an initial substring of increasing length, ... # the string into count-1 partitions. ... #:ops - an array of strings representing the operators to be inserted into ...
    (comp.lang.ruby)
  • Re: Computability and logic
    ... as regards a mathematical formulation of a substring ... substring in a string with another substring? ... result of substituting a term for a variable in a formula'. ... As I recall, he doesn't get into replacing term for term, ...
    (sci.logic)