收到 random.shuffle 第二个参数的警告
Getting a warning for the second argument of random.shuffle
我想使用 random.shuffle
随机化字符串列表。这是一个最小的示例代码:
import random
L = ['a', 'b']
random.shuffle(L, 3.0)
然而,我的 IDE 抱怨第二个参数。它突出显示 3.0
并显示以下警告消息:
Expected type 'Optional[() -> float]', got 'float' instead
这个警告是什么意思?
的文档
random.shuffle(x[, random])
Shuffle the sequence x in place.
The optional argument random is a 0-argument function returning a random float in [0.0, 1.0); by default, this is the function random()
.
(加粗)
我想使用 random.shuffle
随机化字符串列表。这是一个最小的示例代码:
import random
L = ['a', 'b']
random.shuffle(L, 3.0)
然而,我的 IDE 抱怨第二个参数。它突出显示 3.0
并显示以下警告消息:
Expected type 'Optional[() -> float]', got 'float' instead
这个警告是什么意思?
random.shuffle(x[, random])
Shuffle the sequence x in place.
The optional argument random is a 0-argument function returning a random float in [0.0, 1.0); by default, this is the function
random()
.
(加粗)