一日一技:在 Python 裡面的常用常量字元串
- 2019 年 12 月 17 日
- 筆記
import random letter = random.choice('qwertyuiopasdfghjklzxcvbnm') 後來,我知道了,原來程式碼可以這樣寫:
import random import string letter = random.choice(string.ascii_lowercase)
string模組包含了我們常用的一些常量字元串:
- 大小寫字母:
string.ascii_letters - 小寫字母:
string.ascii_lowercase - 大寫字母:
string.ascii_uppercase - 數字0-9:
string.digits - 十六進位數字:
string.hexdigits - 常見特殊符號:
string.punctuation - 看起來像空格的字元:
string.whitespace

