菜鳥教程
https://www.runoob.com/python/python-built-in-functions.html
常用內(nèi)置函數(shù):
輸入輸出:
input
raw_input
print
數(shù)值函數(shù)
abs
sum
pow
sqrt
cmp(x,y) 函數(shù)用于比較2個對象交惯,如果 x < y 返回 -1, 如果 x == y 返回 0, 如果 x > y 返回 1。
round() 方法返回浮點數(shù)x的四舍五入值。
排序查找最大最小
len
min
max
sorted:不會修改原來的類型凉泄,返回排序以后的一個副本秦叛。
reversed:返回翻轉(zhuǎn)以后的一個迭代器轰豆,需要用*解析迷殿。不修改源對象內(nèi)容乱顾,僅僅是返回一個迭代器盟戏。
a = [1,2,3]
b = reversed(a)
print(*b) # 3 2 1
類型轉(zhuǎn)換
str
int
float
long
bool
字符相關(guān):
chr() :
用一個范圍在 range(256)內(nèi)的(就是0~255)整數(shù)作參數(shù)绪妹,返回一個對應(yīng)的字符。
ord() :
函數(shù)是 chr() 函數(shù)(對于8位的ASCII字符串)或 unichr() 函數(shù)(對于Unicode對象)的配對函數(shù)柿究,它以一個字符(長度為1的字符串)作為參數(shù)邮旷,返回對應(yīng)的 ASCII 數(shù)值,或者 Unicode 數(shù)值蝇摸,如果所給的 Unicode 字符超出了你的 Python 定義范圍婶肩,則會引發(fā)一個 TypeError 的異常。
unichr()
函數(shù) 和 chr()函數(shù)功能基本一樣貌夕, 只不過是返回 unicode 的字符律歼。
>>>ord('a')
97
>>> print chr(48), chr(49), chr(99) # 十進制
0 1 c
>>> unichr(99)
u'c'
其他:
range
xrange
id() 函數(shù)用于獲取對象的內(nèi)存地址。
dict()
set()
list()
tuple
與類相關(guān):
vars() 函數(shù)返回對象object的屬性和屬性值的字典對象啡专。
type() 返回類型
isinstance() 函數(shù)來判斷一個對象是否是一個已知的類型险毁,類似 type()。
isinstance(object, classinfo)
isinstance() 與 type() 區(qū)別:
type() 不會認為子類是一種父類類型们童,不考慮繼承關(guān)系畔况。
isinstance() 會認為子類是一種父類類型,考慮繼承關(guān)系慧库。
如果要判斷兩個類型是否相同推薦使用 isinstance()跷跪。