dimanche 20 mars 2016

python how can i getting return '' if object[3] retune value is 'IndexError: list index out of range'

i want gettting '', if object[3] retune value is 'IndexError: list index out of range' is possble??

i use this code

object = [4,5]
print(object[3] if object[3] is not None else '')

this result

>     Traceback (most recent call last):
>       File "<pyshell#5>", line 1, in <module>
>         object[3] if object[3] is not None else ''
>     IndexError: list index out of range

Aucun commentaire:

Enregistrer un commentaire