[ Python - 5 ] 通过random模块生成随机字符串

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[ Python - 5 ] 通过random模块生成随机字符串相关的知识,希望对你有一定的参考价值。

技术分享
import random
checkcode = ‘‘
for i in range(4):
    if i == random.randint(0,3):
        current = chr(random.randrange(65,90))
        checkcode += str(current)
    else:
        checkcode += str(i)

print(checkcode)
View Code

 

以上是关于[ Python - 5 ] 通过random模块生成随机字符串的主要内容,如果未能解决你的问题,请参考以下文章

Python基础(random模块)

Python之路26-random模块

python random 模块

python模块之collections random

day5-Python学习笔记random模块,时间模块,加密模块

Python基础-14模块-random模块