python_ built-in string

May need all integers, write all the letters and other programs, without having to own a new list or string, python comes with strings

import  string

Print (string.digits) # all integers 
Print (string.ascii_letters) # all lowercase and uppercase 
Print (string.ascii_lowercase) # all lowercase 
Print (string.ascii_uppercase) # all uppercase 
Print (string.punctuation) # all special characters


D:\study\python\test\venv\Scripts\python.exe D:/study/python/test/dd.py
0123456789
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~

 

example:

import  string
import  random

Print (random.sample (string.ascii_uppercase,. 4)) # capital letters randomly generated four 
Print (random.sample (string.punctuation,. 8)) # all special characters randomly generated 8


D:\study\python\test\venv\Scripts\python.exe D:/study/python/test/dd.py
['J', 'M', 'C', 'P']
['{', "'", '%', '&', '|', '^', '+', '#']

 

Guess you like

Origin www.cnblogs.com/xiaokuangnvhai/p/11001934.html