【发布时间】:2018-06-08 15:12:42
【问题描述】:
有没有办法在 python3 中获得真正的强类型,这样当使用错误的类型时会出现运行时错误? 请参见以下示例:
def pick(k:int = None):
if k: print("value: ", k)
else: print("no value")
pick()
pick(1000)
pick("error")
这给出了以下输出:
no value <- can be accepted, and for this example it would be useful
value: 1000
value: error <- here should come a runtime error
【问题讨论】: