设为首页 加入收藏

TOP

python之Number(二)
2017-09-30 13:02:29 】 浏览:8160
Tags:python Number
ndom.uniform(10,20) #生成10,20之间的浮点数 19.774883012515218 >>> random.uniform(10,20) 11.654111952867027 >>> random.randint(10,20) #生成指定范围内的整数 18 >>> random.randint(10,20) 11 >>> random.randrange(1,100,8) #从指定范围内按指定基数递增获取随机数 33 >>> random.randrange(1,100,8) 17 >>> random.randrange(1,100,8) 33 >>> random.choice([1,2,3,4,5]) #从序列元素中随机获取元素,只能是有序类型 2 >>> random.choice([1,2,3,4,5]) 1 >>> random.choice([1,2,3,4,5]) 2 >>> random.choice('abcd') 'd' >>> random.choice('abcd') 'a' >>> random.choice('abcd') 'c' >>> a = [1,2,3,4,5] #将一个列表元素打乱 >>> random.shuffle(a) >>> a [1, 2, 3, 5, 4] >>> random.shuffle(a) >>> a [2, 5, 4, 3, 1] >>> random.sample(a,2) #从指定序列中随机获取N个元素,生成新对象 [5, 2] >>> random.sample(a,2) [5, 4] >>> random.sample(a,3) [3, 4, 1] >>> random.sample(a,5) [5, 1, 4, 2, 3]

2017-09-2412:27:23?

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇python之Number 下一篇Flask程序部署--WSGI独立容器

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目