【问题标题】:Getting a warning for the second argument of random.shuffle [closed]收到 random.shuffle 的第二个参数的警告 [关闭]
【发布时间】:2020-08-11 13:36:50
【问题描述】:

我想使用random.shuffle 来随机化一个字符串列表。这是一个最小的示例代码:

import random
L = ['a', 'b']
random.shuffle(L, 3.0)

但是,我的 IDE 抱怨第二个参数。它使用以下警告消息突出显示3.0

Expected type 'Optional[() -> float]', got 'float' instead

这个警告应该是什么意思?

【问题讨论】:

标签: python random typing


【解决方案1】:

来自random.shuffle 的文档

random.shuffle(x[, random])

随机播放序列 x

可选参数 random 是一个 0 参数函数,返回 [0.0, 1.0) 中的随机浮点数;默认情况下,这是函数random()

(加粗)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 2014-11-11
    • 1970-01-01
    • 2021-03-15
    • 1970-01-01
    相关资源
    最近更新 更多