開始使用免費開始

使用 string 模組

最近你看過幾個常用的模組,包括 string。它可以彙整特定的值(例如所有大寫字元),或用來格式化文字。

當你需要檢查文字是否包含特定字元,或要修改文字(例如轉成小寫)時,這會很有幫助。

在本練習中,你會匯入這個模組,並存取它的 ascii_lowercasepunctuation 屬性。

本練習屬於課程

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.____)
編輯並執行程式碼