Python3 shuffle() 函数
Python 3 教程
· 2019-02-05 16:11:32
描述
shuffle() 方法将序列的所有元素随机排序。
语法
以下是 shuffle() 方法的语法:
import random
random.shuffle (lst )
注意:shuffle()是不能直接访问的,需要导入 random 模块,然后通过 random 静态对象调用该方法。
参数
- lst -- 列表。
返回值
返回 None。
实例
以下展示了使用 shuffle() 方法的实例:
实例
#!/usr/bin/python3
import random
list = [20, 16, 10, 5];
random.shuffle(list)
print ("随机排序列表 : ", list)
random.shuffle(list)
print ("随机排序列表 : ", list)
以上实例运行后输出结果为:
随机排序列表 : [20, 5, 16, 10] 随机排序列表 : [5, 20, 10, 16]
点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html
Dive Into Python 3
Mark Pilgrim / Apress / 2009-11-6 / USD 44.99
Mark Pilgrim's Dive Into Python 3 is a hands-on guide to Python 3 (the latest version of the Python language) and its differences from Python 2. As in the original book, Dive Into Python, each chapter......一起来看看 《Dive Into Python 3》 这本书的介绍吧!