python-生成密码(37)

news/2024/7/3 4:02:13
from random import choice
import string

all_chs = string.ascii_letters + string.digits

def gen_pass(n=8):  #默认是循环8次,也就是生成8位密码
    result = ''
    for i in range(n):
        ch = choice(all_chs)
        result +=ch
    return result

if __name__ == '__main__':
    print(gen_pass())
    print(gen_pass(4))  #生成4位的密码
    print(gen_pass(10)) #生成10位的密码


# 解释
# >>> import string
# >>> string.ascii_letters
# 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
# >>> string.digits
# '0123456789'

# 测试
# [root@zhuji pyrhon百例]# python3 37生成密码验证密码.py
# FsOHGZ87
# BNhA
# Q0wO0ANAzg

http://www.niftyadmin.cn/n/3433360.html

相关文章

React 18已经发布,新特性一览,带你快速了解。

React 18已经发布,新特性一览,带你快速了解。 react 18 已经发布。 1.新增了useId,startTransition,useTransition,useDeferredValue,useSyncExternalStore,useInsertionEffect等新的 hook API…

centos编译安装zlib

2019独角兽企业重金招聘Python工程师标准>>> 先到官网下载(比如下载1.2.11版本): http://www.zlib.net/ 然后将tar包解压到 /usr/local/zlib。 切换到/usr/local/zlib/zlib-1.2.11 ./configure make && make install 转载于:https://my.oschina.…

[LeetCode]3Sum Closest

题目描述:(链接) Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution. For example, given array …

recv()

说明我的想法之前,我先纠正一下上面我犯的几个错误,也许说明这些错误对楼主也有帮助。且听我慢慢道来,嘿嘿我的犯的最大错误是,没有搞清楚“模式”和“选项”,BLOCK是一种模式,而TIMEOUT只是一个在特定模式…

crontab-ui 管理 crontab

背景 以前在做定时任务的时候,都需要上网查一下怎么配置 crontab,因为这个东西不常用而且使用功能间隔可能会很长,每次需要用的时候可能都忘记上次是怎么用的,所以每次都需要去查怎么配置使用。这里介绍一个工具 crontab-ui 帮助…

python-序列对象方法(38)

>>> from random import randint >>> alist list() >>> list(hello) [h, e, l, l, o] >>> list((10,20,30)) #元组转换成列表 [10, 20, 30]>>> astr str() >>> str(10) #将数字转换成字符串 10 >>> str…

文件分片上传,断点续传

为什么文件要分片上传? 当单文件过大时,因为传输和后端处理文件时间过长都会导致时间过长,如果代理服务器没有在期望时间内获得后端处理程序返回内容,就会向前端抛出timeout错误。所以文件过大,需要对文件进行拆分,分…

ubuntu下SSH免密码登录设置

SSH服务器端:AA的SSH端口:portAA的用户名:nameAA的IP:IPA SSH访问端:BB的用户名:nameBB的IP:IPB效果:B通过SSH访问A1)确认ssh是否安装(通过重启来确认&#x…