There are a lot of places to use random characters, such as login site random verification code, through the random module can easily generate random string
Import Randomprint (Random.randrange (1, ten)) # Returns a random number between 1-10, excluding 10print (Random.randint (1, ten)) # Returns a random number between 1-10, including 10print (Random.randrange (0, 2)) # randomly selects even print (random.random) # between 1 and 100 to return the random floating-point print ( Random.choice (' abce3#&@1 ') # Returns a random character in a given data set print (Random.sample (' Abcdefghij ', 3)) # Select a specific number of characters from multiple characters # Generate random string import stringstr1 = '. Join (Random.sample (String.ascii_lowercase + string.digits, 6)) print (STR1) # Shuffle A = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]print (Random.shuffle (a))
Getting started with Python: Common modules-random Modules