Today, I want to change the server password. I don't know what password to set. Set a random number simply. The random module in python can generate random numbers. This is mainly used to generate random passwords.
By the way, there are three functions in the string module: string. letters, string. printable, string. printable. Below are the outputs of these functions. You can take a look at them. You don't need to talk about them more:
1234567 >>>> importstring >>> string. letters 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz '>>> string. digits '000000' >>> string. printable' success! "# $ % & \ '() * +,-./:; <=>? @ [\] ^ _ '{| }~ \ T \ n \ r \ x0b \ x0c'
The following describes how to randomly generate 10 groups of random numbers containing numbers and uppercase/lowercase letters. You can specify the length of a random number:
1234567891011121314151617 #-*-coding: UTF-8-*-''' generate a random password briefly, including uppercase and lowercase letters and numbers, you can specify the password length ''' # generate the random password importrandomimportstring # string in python3. ascii_letters, and string can be used in python2. letters and string. ascii_lettersdefGenPassword (length): chars = string. ascii_letters + string. digitsreturn ''. join ([random. choice (chars) foriinrange (length)]) # The returned result contains repeated characters # return ''. join (random. sample (chars, 15) # No repeated if _ name __= = "_ main _" characters exist in the result __": # generate 10 random passwords foriinrange (10): # The password length is 15 printGenPassword (15)