
例如以下程式示範三個模組
# 示範時間相關模組
from datetime import date
print(date.today())
# 示範數學相關模組
from math import log
print(log(1024, 2))
# 示範正規運算式相關模組
import re
print(re.search("o", "dog"))
# 《程式語言教學誌》的範例程式
# http://pydoing.blogspot.com/
# 檔名:stddemo.py
# 功能:示範 Python 程式
# 作者:張凱慶
# 時間:西元 2012 年 12 月 執行結果如下

另外像預設的浮點數會有誤差,這時使用 decimal 就可以避免誤差的產生,例如
from decimal import *
print()
print(round(0.7 * 1.05, 2))
print(round(Decimal("0.7") * Decimal("1.05"), 2))
print()
print(1.00 % 0.10)
print(Decimal("1.00") % Decimal("0.10"))
print()
print(1 / 7)
print(Decimal("1") / Decimal("7"))
print()
# 《程式語言教學誌》的範例程式
# http://pydoing.blogspot.com/
# 檔名:stddemo2.py
# 功能:示範 Python 程式
# 作者:張凱慶
# 時間:西元 2012 年 12 月 程式執行結果如下

有些誤差很小,有些誤差難以預期,反而使用標準程式庫的 decimal 就沒有誤差的問題了。
其他還有日期、資料庫、網路處理、圖形介面...等等,有很多很多有用的東西都在裡頭。對了,我們要為 Encrypt 類別設計一個圖形介面 (graphical interface) , Python 的標準模組庫亦有提供一個圖形介面的程式庫 Tk ,我們先來看看 GUI 的基本概念囉!
| 中英文術語對照 | |
|---|---|
| 標準模組庫 | standard library |
| 圖形介面 | graphical interface |
您可以繼續參考
軟體開發
相關目錄
回 Python 入門指南
回 Python 教材
回首頁
參考資料
http://docs.python.org/3.1/tutorial/stdlib.html
http://docs.python.org/3.1/tutorial/stdlib2.html
沒有留言:
張貼留言