Create a custom function like so:
def get_element(object, index, fallback):
try:
return object[index]
except IndexError:
return fallback
Then, you call:
get_element(foo_val, 3, None)
And if 3 is in range, it returns the correct value; if not, it returns None
.