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

Use python to randomly generate 6-digit password example code

高洛峰
高洛峰Original
2017-03-22 11:44:374136browse

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) #转换成字符串

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!

Statement:
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