I have array, which I want to validate, 2nd item of that array. There are 2 ways which comes to my mind
-
Check for
arraylenghtif len(array) > 1: # Process for array[1] -
Catch
IndexErrorand process inelseblock.try: array[1] except IndexError: pass else: # Process for array[1]
Which one is better?
If you have any other option, I am ready to learn :)
Aucun commentaire:
Enregistrer un commentaire