我是靠谱客的博主 年轻唇膏,这篇文章主要介绍Python笔记之random模块!,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#random模块 import random import string print(random.randint(10,100)) print(random.randrange(10,100,5)) #数字5是步长 print(random.random()) #返回随机浮点数 print(random.choice('asdasdafafaf')) #返回字符串的随机一个 print(random.sample(range(1,31),5)) #从多个对象中随机返回指定个对象 print(string.digits + string.ascii_lowercase) print(''.join(random.sample((string.digits + string.ascii_lowercase),5))) #随机生成网站验证码 a = list(range(10)) random.shuffle(a) #打乱原有列表的顺序 print(a)

输出结果:

复制代码
1
2
3
4
5
6
7
8
9
10
11
49 35 0.5636116539682788 a [3, 15, 28, 16, 12] 0123456789abcdefghijklmnopqrstuvwxyz ajxen [3, 0, 9, 1, 5, 2, 7, 4, 8, 6] Process finished with exit code 0

最后

以上就是年轻唇膏最近收集整理的关于Python笔记之random模块!的全部内容,更多相关Python笔记之random模块内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(62)

评论列表共有 0 条评论

立即
投稿
返回
顶部