T
TkNeo
WHAT ?
This is crazy
This is crazy
WHAT ?
This is crazy
TkNeo said:WHAT ?This is crazy
Crazy like a fox?
a = [1, 2, 3]
try:
a.index(99)
except:
a.append(99)
finally:
print a.index(99)
MY question: which exception should I actually be catching there?
ofcouse try catch is going to work but in ideality the index function
should return a -1 and no way in hell crash.
Crazy like a fox?a = [1, 2, 3]
try:
a.index(99)
except:
a.append(99)
finally:
print a.index(99)MY question: which exception should I actually be catching there?
ofcouse try catch is going to work but in ideality the index function
should return a -1 and no way in hell crash.
The generally used idiom for that is:
lst = ['a', 'b', 'c']
if 'a' in lst:
foo = lst.index('a')
On May 2, 1:58 pm, Nick J Chackowsky <[email protected]>
wrote:TkNeo wrote:
WHAT ?
This is crazy
Crazy like a fox?
a = [1, 2, 3]
try:
a.index(99)
except:
a.append(99)
finally:
print a.index(99)
MY question: which exception should I actually be catching there?ofcouse try catch is going to work but in ideality the index function
should return a -1 and no way in hell crash.
Please refrain from making such inane comments after an hour or two of
toying with a new language. Read a good tutorial first (e.g.http://diveintopython.org/toc/index.html) and come back if you have a
real question.
George
The generally used idiom for that is:lst = ['a', 'b', 'c']
if 'a' in lst:
foo = lst.index('a')
Jeff - Gracias !!
I am fairly new to python. Thanks for the example code snippet above.
It is the same amount of code as receiving -1 and then checking for
doing an "if else" for -1 so now i don't feel bad. But, being new to
this paradigm, raising of an exception when it can't find the element
appears to be weird to me for some unexplainable reason.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.