使用 string 模組
最近你看過幾個常用的模組,包括 string。它可以彙整特定的值(例如所有大寫字元),或用來格式化文字。
當你需要檢查文字是否包含特定字元,或要修改文字(例如轉成小寫)時,這會很有幫助。
在本練習中,你會匯入這個模組,並存取它的 ascii_lowercase 與 punctuation 屬性。
本練習屬於課程
Intermediate Python for Developers
練習說明
- 匯入 string 模組。
- 存取該模組的
.ascii_lowercase屬性。 - 存取該模組的
.punctuation屬性。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the string module
____ string
# Print all ASCII lowercase characters
print(string.____)
# Print all punctuation
print(string.____)