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

yipeiwu_com5年前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 脚本生成随机 字母 + 数字密码功能,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

相关文章

Python中__repr__和__str__区别详解

看下面的例子就明白了 class Test(object): def __init__(self, value='hello, world!'): self.data =...

Python的Bottle框架中返回静态文件和JSON对象的方法

Python的Bottle框架中返回静态文件和JSON对象的方法

代码如下: # -*- coding: utf-8 -*- #!/usr/bin/python # filename: todo.py # codedtime: 2014-8-28...

python学习教程之Numpy和Pandas的使用

python学习教程之Numpy和Pandas的使用

前言 本文主要给大家介绍了关于python中Numpy和Pandas使用的相关资料,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。 它们是什么? NumPy是Pytho...

python3实现ftp服务功能(服务端 For Linux)

python3实现ftp服务功能(服务端 For Linux)

本文实例为大家分享了python3实现ftp服务功能的具体代码,供大家参考,具体内容如下 功能介绍: 可执行的命令: ls pwd cd put rm get mkdir 1、...

Python标准库使用OrderedDict类的实例讲解

目标:创建一个字典,记录几对python词语,使用OrderedDict类来写,并按顺序输出。 写完报错: [root@centos7 tmp]# python python_ter...