严格传入函数的参数类型,并自定义抛出异常

案例:Python将函数作为参数以及作为返回值

执行结果:

33
44
99
Traceback (most recent call last):
  File "functions.py", line 34, in <module>
    print res2(44, "55")
  File "functions.py", line 8, in sum
    raise  "Parameter type error, two parameter types must be integer"
TypeError: exceptions must be old-style classes or derived from BaseException, not str

相关文章: