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.
Learn Flask development and learn to build cool apps with our premium Python course on Udemy.