复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#coding:utf8 import random # 随机生成0到1之间的浮点数 a=random.random() print(a) # 随机生成固定范围的浮点数 b=random.uniform(1, 10) print(b) # 取字符串中随机一个字符 c=random.choice('abcdefg&#%^*f') print(c) #取字符串中随机多个字符,生成列表 d=random.sample('abcdefghij',3) print(d) #随机排序 items = [1, 2, 3, 4, 5, 6] random.shuffle(items) print(items)
复制代码
1输出结果分别为:
复制代码
1
2
3
4
5
6
7
8
9
10C:Python27python.exe C:/Users/gf/Desktop/python草稿测试/111.py 0.909766091683 6.36188760688 # ['h', 'i', 'j'] [1, 5, 2, 4, 3, 6] Process finished with exit code 0
最后
以上就是开心钢笔最近收集整理的关于python 随机生成整数 浮点数 字符 排序 简单案例的全部内容,更多相关python内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复