import random import string def generate_random_string(string_length): letters_and_digits = string.ascii_uppercase + string.digits return ''.join(random.choice(letters_and_digits) for i in range(string_length)) print(generate_random_string(10))
WYBAV2OJFZ
In Python, you can generate a random string with upper case letters and digits using the random module and string methods.
The code above uses the string.ascii_uppercase and string.digits constants to define a string of all upper case letters and digits. The random.choice function is used to randomly select characters from this string, and the join method is used to concatenate the selected characters into a single string. The resulting string is returned by the generate_random_string function.
Python Mega Course: Learn Python in 60 Days, Build 20 Apps
Learn Python on Udemy completely in 60 days or less by building 20 real-world applications from web development to data science.