Generate Random 8-Digit Password with Python

You can generate a random password with 8 digits using the randint() function in the random module. Here is an example code:

import random

def generate_password():
    password = ""
    for _ in range(8):
        password += str(random.randint(0, 9))
    return password

print(generate_password())

Running the above code will output a randomly generated 8-digit password. Each time the code is run, a different password will be generated.

bannerAds