如何一行打印?

时间:2019-11-09 11:39:43

标签: python-3.x

我的问题是:如何以一行或一行打印密码? 我想知道如何在一行中打印输出。 我的代码是:

import random
import string

char = string.ascii_letters + string.digits + string.punctuation
lenght = random.randint(8, 16)

for i in range(lenght) :
    password = ''.join(random.choice(char))

    print('your password is === > ', password)

1 个答案:

答案 0 :(得分:1)

我找到了一种方法,将字母打印在一行上

import random
import string
char = string.ascii_letters + string.digits + string.punctuation
lenght = random.randint(8, 16)  
password = ''.join(random.choice(char) for x in range(lenght))
print('your password is === > ',password)