In Python a way to calculate the max of a list and output a value even with an empty list is to do this:
max(python_list, default=0)
Is there any similar way (in one statement and obviously without try
and except
or if
and else
) in Python to calculate the average?
I used this simple code:
average = sum(python_list)/ len(python_list)
and obviously I get this error with an empty list:
ZeroDivisionError: division by zero