內建與模組函式庫

Python 有內建的標準函式庫 (Standard Library) ,這標準函式庫是非常龐大。除標準函式庫之外,還有成千上萬且不斷增加的模組函式庫。這裡我們只介紹一些常用的。

內建函式

Python 提供許多的內建函式庫

內建函式如 input()、print()、eval()、int()、float()、str()、len()、any()、all()等等。內建函式清單可參考:python-doc-tw.github.io/library/functions.html 。僅列出常用的函式庫。

模組函式庫

Python 提供了許多模組函式庫

例如:數學模組的 math、產生各種不同分配隨機數的 random 模組。使用時必須先 import 進來。模組函式庫可參考:https://python-doc-tw.github.io/py-modindex.html#cap-r 。使用方法為模組名字.函數,例如 math 模組的 pow(2,3) 函數,要用 math.pow(2,3),而且用之前必須 import math。下表僅列出常用的 math 模組函式。

範例使用 import math

範例使用 import math as m 取了別名 m。