Home > Backend Development > Python Tutorial > Use python to randomly generate 6-digit password example code

Use python to randomly generate 6-digit password example code

高洛峰
Release: 2017-03-22 11:44:37
Original
4153 people have browsed it

This article explains in detail how to use python to randomly generate a 6-digit password example code

#!/usr/bin/env python
# -*- coding: UTF-8 -*- 
import random
#生成随机6位随机数含字母
code = []
for i in range(6):
    if i == random.randint(1,5):
        code.append(str(random.randint(1,5)))
    else:
        code.append(chr(random.randint(65,90)))
print ''.join(code) #转换成字符串
Copy after login

The above is the detailed content of Use python to randomly generate 6-digit password example code. 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