Describes the use of random and string, based on.
Sting:------------------gets to 0-9 10 numbers and 26 lowercase letters, altogether 62.
String.printable:
>>>string.printable>>> ' 0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz! ' #$%&\ ' () *+,-./:;<=>[email protected][\\]^_ ' {|} ~ \t\n\r\x0b\x0c ' >>> text=string.printable>>> text ' 0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz! " #$%&\ ' () *+,-./:;<=>[email protected][\\]^_ ' {|} ~ \t\n\r\x0b\x0c ' >>> text[0:62] ' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '
2. After acquiring 62 characters, randomly select 4 characters from these characters.
Random:---------------random.sample (text[0:62],4):
>>> random.sample (text[0:62],4) [' K ', ' Q ', ' I ', ' S ']
3. Aggregate into string sting.
>>> yzcode= "". Join (Random.sample (text[0:62],4)) >>> yzcode ' 0vfN ' >>> yzcode= "". Join ( Random.sample (text[0:62],4)) >>> yzcode ' frjq ' >>> yzcode= "". Join (Random.sample (text[0:62],4)) >>> yzcode ' ez1q ' >>> yzcode= "". Join (Random.sample (text[0:62],4)) >>> yzcode ' QFTG '
4. The next time will be implemented to write the generated verification code to the picture, has reached the function of the real verification code.
Python generates a verification code that's simple: random and Srting methods