random.choice(seq)

简介: random.choice(seq)
  1. random.choice(seq):从序列中随机选择一个元素
    例子:
import random
fruits = ["apple", "banana", "orange"]
fruit = random.choice(fruits)
print(fruit)


相关文章
|
27天前
|
数据采集 Python
【随手记】np.random.choice()函数
【随手记】np.random.choice()函数
19 0
|
2月前
|
Linux Windows
【已解决】ValueError: num_samples should be a positive integer value, but got num_samples=0
【已解决】ValueError: num_samples should be a positive integer value, but got num_samples=0
|
2月前
random.random()
random.random()
27 1
|
2月前
random.randint(a, b)
random.randint(a, b)
30 1
|
2月前
numpy.random.rand(d0, d1, …, dn)
numpy.random.rand(d0, d1, …, dn)
22 0
|
2月前
random.sample(population, k)
random.sample(population, k)
22 0
|
2月前
|
安全
secrets.choice(seq)
secrets.choice(seq)
17 0
|
2月前
random.shuffle(lst)
random.shuffle(lst)
22 0
|
11月前
Random
Random
37 0
|
11月前
|
Python
Python random 随机函数(random、uniform、randint、choice、choices、randrange、shuffle、sample)
Python random 随机函数(random、uniform、randint、choice、choices、randrange、shuffle、sample)
90 0