【发布时间】:2011-11-24 20:55:12
【问题描述】:
由于我刚从 C++ 切换到 Python,感觉 Python 不太关心类型安全。例如,谁能向我解释为什么在 Python 中不需要检查函数参数的类型?
假设我定义了一个 Vector 类如下:
class Vector:
def __init__(self, *args):
# args contains the components of a vector
# shouldn't I check if all the elements contained in args are all numbers??
现在我想在两个向量之间做点积,所以我添加了另一个函数:
def dot(self,other):
# shouldn't I check the two vectors have the same dimension first??
....
【问题讨论】:
-
这里是如何做到这一点的答案stackoverflow.com/questions/378927/…
标签: python