python 脚本生成随机 字母 + 数字密码功能

yipeiwu_com7年前Python基础

下面一段代码给大家介绍python 脚本生成随机 字母 + 数字密码功能,具体代码如下所述:

#coding:utf-8
import random,string
def GetPassword(length):
  # 随机生成数字个数
  Ofnum=random.randint(1,length)
  Ofletter=length-Ofnum
  # 选中ofnum个数字
  slcNum=[random.choice(string.digits) for i in range(Ofnum)]
  # 选中ofletter个字母
  slcLetter=[random.choice(string.ascii_letters) for i in range(Ofletter)]
  # 打乱组合
  slcChar=slcLetter+slcNum
  random.shuffle(slcChar)
  # 生成随机密码
  getPwd=''.join([i for i in slcChar])
  return getPwd
if __name__=='__main__':
  print( GetPassword(6)) #GetPassword()自定义随机密码长度

总结

以上所述是小编给大家介绍的python 脚本生成随机 字母 + 数字密码功能,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

相关文章

pandas 读取各种格式文件的方法

pandas 读取各种格式文件: 前置工序: import pandas as pd csv 文件读取中文错误处理: utf-8 codec can't decode .... pd...

Python使用pyshp库读取shapefile信息的方法

通过pyshp库,可以读写Shapefile文件,查询相关信息,github地址为 https://github.com/GeospatialPython/pyshp import...

python 不以科学计数法输出的方法

其实很简单只需两个语句: import numpy as np np.set_printoptions(suppress=True) 这样就可以搞定 以上这篇python 不以科学...

python gdal安装与简单使用

python gdal安装与简单使用

gdal安装 方式一:在网址 https://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载对应python版本的whl文件,在命令行中pip instal...

Python3.7+tkinter实现查询界面功能

Python3.7+tkinter实现查询界面功能

Tkinter 是 Python 的标准 GUI 库。Python 使用 Tkinter 可以快速的创建 GUI 应用程序。 这篇文章使用tkinter实现一个简单的查询界面 #!/...