Python:如何修复参数类型?

时间:2018-07-20 13:17:18

标签: python python-3.x

如何在Python中修复参数类型?

def truncus(fill=int):
    return [i for i in range(fill)]

1 个答案:

答案 0 :(得分:2)

def truncus(fill):
  if type(fill) != int:
    raise Exception("A non-integer value was passed to truncus.")
  return [i for i in range(fill)]