Getting a default value on index out of range in Python

Posted by zjm1126 on Stack Overflow See other posts from Stack Overflow or by zjm1126
Published on 2010-04-04T14:10:17Z Indexed on 2010/04/04 14:33 UTC
Read the original article Hit count: 321

Filed under:
|
a=['123','2',4]
b=a[4] or 'sss'
print b

I want to get a default value when the list index is out of range (here: 'sss').

How can I do this?

© Stack Overflow or respective owner

Related posts about list

Related posts about python