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

查看所有标签

Nginx Essentials

Nginx Essentials

Valery Kholodkov / Packt Publishing / 2015-7-1 / USD 34.99

About This Book Learn how to set up, configure, and operate an Nginx installation for day-to-day useExplore the vast features of Nginx to manage it like a pro, and use them successfully to run your......一起来看看 《Nginx Essentials》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

SHA 加密
SHA 加密

SHA 加密工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具