内容简介:shuffle() 方法将序列的所有元素随机排序。
描述
shuffle() 方法将序列的所有元素随机排序。
语法
以下是 shuffle() 方法的语法:
import random random.shuffle (lst )
注意:shuffle()是不能直接访问的,需要导入 random 模块,然后通过 random 静态对象调用该方法。
参数
- lst -- 可以是一个序列或者元组。
返回值
返回随机 排序 后的序列。
实例
以下展示了使用 shuffle() 方法的实例:
#!/usr/bin/python # -*- coding: UTF-8 -*- import random list = [20, 16, 10, 5]; random.shuffle(list) print "随机排序列表 : ", list random.shuffle(list) print "随机排序列表 : ", list
以上实例运行后输出结果为:
随机排序列表 : [16, 5, 10, 20] 随机排序列表 : [16, 5, 20, 10]
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- Python 拓展之特殊函数(lambda 函数,map 函数,filter 函数,reduce 函数)
- Python 函数调用&定义函数&函数参数
- python基础教程:函数,函数,函数,重要的事说三遍
- C++函数中那些不可以被声明为虚函数的函数
- 017.Python函数匿名函数
- 纯函数:函数式编程入门
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Pattern Recognition and Machine Learning
Christopher Bishop / Springer / 2007-10-1 / USD 94.95
The dramatic growth in practical applications for machine learning over the last ten years has been accompanied by many important developments in the underlying algorithms and techniques. For example,......一起来看看 《Pattern Recognition and Machine Learning》 这本书的介绍吧!