您可以使用random模块中的randint()函数生成一个8位数的随机密码。以下是一个示例代码:
import random
def generate_password():
password = ""
for _ in range(8):
password += str(random.randint(0, 9))
return password
print(generate_password())
运行上述代码,它将输出一个随机生成的8位数密码。每次运行代码时,生成的密码都会不同。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: python中set的含义是什么