示例代码表单scipy document :
from scipy.stats import norm
numargs = norm.numargs
[ ] = [0.9,] * numargs
rv = norm()
我完全不明白第三行在这里做什么。谁能解释一下吗?
最佳答案
我称这为恶作剧。因此 numargs
的类型为 int
,如果它是 0
以外的任何类型,则此代码将失败。本质上,这段代码只是 []=[]
,对我来说这似乎完全没有意义。
这可能只是文档中的遗留内容,因为其他地方会出现以下内容:
>>> from scipy.stats import nct
>>> numargs = nct.numargs
>>> [ df, nc ] = [0.9,] * numargs
>>> rv = nct(df, nc)
也许这些示例是自动生成的。由于所有其他发行版示例都具有类似的格式。
关于 python : Any use of this assignment to an empty list?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22729421/