
- Python - 文字處理
- Python - 文字處理簡介
- Python - 文字處理環境
- Python - 字串不可變性
- Python - 排序行
- Python - 重新設定段落格式
- Python - 統計段落中的標記
- Python - Binary ASCII 轉換
- Python - 字串作為檔案
- Python - 向後檔案讀取
- Python - 過濾重複詞
- Python - 從文字中提取電子郵件
- Python - 從文字中提取 URL
- Python - 美化列印
- Python - 文字處理狀態機
- Python - 大小寫和翻譯
- Python - 標記化
- Python - 去除停用詞
- Python - 同義詞與反義詞
- Python - 文字翻譯
- Python - 單詞替換
- Python - 拼寫檢查
- Python - WordNet 介面
- Python - 語料庫訪問
- Python - 單詞標記
- Python - 塊和缺口
- Python - 塊分類
- Python - 文字分類
- Python - 二元組
- Python - 處理 PDF
- Python - 處理 Word 文件
- Python - 閱讀 RSS 源
- Python - 情感分析
- Python - 搜尋和匹配
- Python - 文字修改
- Python - 文字包裝
- Python - 頻率分佈
- Python - 文字總結
- Python - 詞幹演算法
- Python - 受限搜尋
Python - 大小寫和翻譯
在任何文字處理系統中,大寫字串都是一個常見需求。Python 透過使用標準庫中的內建函式來實現此目的。在下面的示例中,我們使用兩個字串函式 capwords() 和 upper() 來實現此目的。其中“capwords”將每個單詞的首字母大寫,“upper”將整個字串大寫。
import string text = 'Tutorialspoint - simple easy learning.' print string.capwords(text) print string.upper(text)
當我們執行以上程式時,將得到以下輸出 −
Tutorialspoint - Simple Easy Learning. TUTORIALSPOINT - SIMPLE EASY LEARNING.
在 python 中,翻譯基本上是指用另一個字母替換特定字母。它可用於加密和解密字串。
import string text = 'Tutorialspoint - simple easy learning.' transtable = string.maketrans('tpol', 'wxyz') print text.translate(transtable)
當我們執行以上程式時,將得到以下輸出 −
Tuwyriazsxyinw - simxze easy zearning.
廣告