Evaluating,
max_val = max(a)
will cause the error,
ValueError: max() arg is an empty sequence
Is there a better way of safeguarding against this error other than a try
, except
catch?
a = []
try:
max_val = max(a)
except ValueError:
max_val = default
Bonus: