Pythonde Rando模块
2015-11-27 20:26
555 查看
# coding=utf-8 ''' Created on 2015-8-14 @author: Administrator ''' import random #randint 在一个范围内生成一个随机int print random.randint(1,80) # 生成一个随机浮点数 print random.uniform(-10,10) # 从sequence中随机获取一个元素,sequence可以是字符串,list ,tuple print random.choice("123sdfgssfs424") # sample从list中随机选取指定个数元素,生成新的list list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] slice = random.sample(list, 5) #从list中随机获取5个元素,作为一个片断返回 print slice print list #原有序列并没有改变。 #random.shuffle的函数原型为:random.shuffle(x[, random]),用于将一个列表中的元素打乱。如: p = ["Python", "is", "powerful", "simple", "and so on..."] random.shuffle(p) print p
相关文章推荐
- Pythoner使用的豆瓣pip源
- Logistic Regression Classifier实现 (Python)
- Python 基础内容五
- python基础-第三方模块PIL_绘图,验证码
- 安装常见python包,出现的问题,及其解决的办法
- windows运行py多线程报错问题
- python内置函数
- python列表,字典
- python基础-常用内建模块
- python tornado coroutine 原理
- selenium自动化测试(python)
- [python]打开文件操作open用法
- Python基础——@staticmethod与@classmethod
- Python与硬件学习笔记:超声波
- python和java中Des加密初试
- Python爬虫实战(二):爬百度贴吧
- Python 编码风格指南中译版(Google SOC)
- Ubuntu 装python3,但是不要改动系统默认python解释器的版本,源码安装的步骤
- 【Python】构造函数、析构函数与可变参数传递
- python 异常处理