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

查看所有标签

The Art of Computer Programming, Volume 2

The Art of Computer Programming, Volume 2

Knuth, Donald E. / Addison-Wesley Professional / 1997-11-04 / USD 79.99

Finally, after a wait of more than thirty-five years, the first part of Volume 4 is at last ready for publication. Check out the boxed set that brings together Volumes 1 - 4A in one elegant case, and ......一起来看看 《The Art of Computer Programming, Volume 2》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

MD5 加密
MD5 加密

MD5 加密工具