Home > Backend Development > Python Tutorial > Introduction to how to use python to generate a password with a specified number of digits

Introduction to how to use python to generate a password with a specified number of digits

高洛峰
Release: 2017-03-22 10:22:08
Original
1588 people have browsed it

This article shares an introduction to the method of generating a password with a specified number of digits using python

#!/usr/bin/env python
#coding:utf8
#随机生成8位、20位、10位密码
import random
import string
all_chs = string.letters + string.digits

def gen_pass(num=8):
    pwd = ''
#    num = int(raw_input('numer: '))
    for i in range(num):
        mima = random.choice(all_chs)
        pwd += mima
    return pwd
if name  == 'main' :
    print gen_pass()
    print gen_pass(20)
    print gen_pass(10)
Copy after login

The above is the detailed content of Introduction to how to use python to generate a password with a specified number of digits. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template