- Python - 文字處理
- Python - 文字處理簡介
- Python - 文字處理環境
- Python - 字串不可變性
- Python - 排序行
- Python - 重新格式化段落
- Python - 計算段落中的單詞數量
- Python - 二進位制 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 feed
- Python - 情感分析
- Python - 搜尋和匹配
- Python - 調整文字
- Python - 換行
- Python - 頻率分佈
- Python - 文字摘要
- Python - 詞幹演算法
- Python - 受限搜尋
Python - 文字翻譯
隨著面向國際受眾的各類網站不斷湧現,從一種語言翻譯成另一種語言變得越來越普遍。Python 提供名為 translate 的軟體包助我們實現這一功能。
可透過以下方法安裝此軟體包。它支援主流語言的翻譯。
pip install translate
下面顯示了一個簡單的句子從英語翻譯成德語的示例,其中英語為預設源語言。
from translate import Translator
translator= Translator(to_lang="German")
translation = translator.translate("Good Morning!")
print translation
執行上述程式後,將看到以下輸出 -
Guten Morgen!
任意兩種語言間
如果需要指定源語言和目標語言,我們可按如下程式中的方式指定。
from translate import Translator
translator= Translator(from_lang="german",to_lang="spanish")
translation = translator.translate("Guten Morgen")
print translation
執行上述程式後,將看到以下輸出 -
Buenos días
廣告