标签:ret def values except return rod exce val for
import numpy as np
print (np.mean(my_list))
def getmean(numericValues):
return sum(numericValues)/len(numericValues) if len(numericValues) > 0 else float(‘nan‘)
my_list = [2,2,4,4,6,6,8,8]
print("{!s}".format(getmean(my_list)))
5.0 5.0
def getmean(numericValues):
return sum(numericValues)/len(numericValues)
my_list2 = []
try:
print("Output :{}".format(getmean(my_list2)))
except ZeroDivisionError as detail:
print("Output :{}".format(float(‘nan‘)))
print("Ouputt : {}".format(detail))
Output :nan Ouputt : division by zero
标签:ret def values except return rod exce val for
原文地址:https://www.cnblogs.com/wei23/p/13162084.html