码迷,mamicode.com
首页 > 编程语言 > 详细

python取字母以及数字随机数

时间:2019-09-03 14:49:49      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:and   dom   string   序列   span   rand   strong   letter   输出   

一、这里用到了:String模块ascii_letters和digits

‘‘.join(random.sample(string.ascii_letters + string.digits, 9))
1、random.sample(string.ascii_letters + string.digits, 9)表示随机抽取9位
2、str.join以某字符串,把抽取的字符连接起来
str = "-"; seq = ("a", "b", "c");
# 字符串序列
print str.join( seq );
输出a-b-c

python取字母以及数字随机数

标签:and   dom   string   序列   span   rand   strong   letter   输出   

原文地址:https://www.cnblogs.com/liudieluo/p/11452911.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!