Parser needed.
Skybuck Flying
skybuck2000 at hotmail.com
Tue Jun 2 13:09:26 EDT 2015
"MRAB" wrote in message
news:mailman.71.1433263397.13271.python-list at python.org...
On 2015-06-02 05:45, Skybuck Flying wrote:
> Example for python:
>
> MyString = "Hello World"
>
> print MyString.rfind("World")
> if MyString.rfind("World"):
> print "yes"
> else:
> print "no"
>
> Pretty cool.
>
"
.rfind returns the index if found, -1 if not found.
"World".rfind("World") returns 0, which will be treated as false.
"foo".rfind("World") returns -1, which will be treated as true.
"
Yes I agree, that code is not very clean.
Hence I added:
print MyString.rfind("World")
Just to figure out if it indeed prints an index.
Index 0 might be of use too, so checking for true/false like I did above
should not be done.
Consider it incorrect code.
However I didn't care at the time cause I was in a hurry... I knew it was
dirty but this post correct that and warns people not to write code like I
did... just in case ! ;)
And also to let you know I am full aware of the shady nature of this code !
;) =D
Bye,
Skybuck :)
More information about the Python-list
mailing list