1. 程式人生 > >2.0 python內建函式

2.0 python內建函式

在ipython下檢視python內建函式_builtin_. \tab補全可以檢視

可以到python官網上去檢視 https://docs.python.org/2.7/

abs(number) \\\返回數字絕對值
max(interable,\[,key=func\])
min(interable,\[,key=func\]) \\\返回最大(最小)值
max('123')返回3 max(\[1,2,3\])返回3
max('123a','231')會返回長的字串
len() 返回字串長度
divmod() 返回兩個數的商和餘數
pow(x, y, z=None) x的y次方,然後對z取餘
round(number, ndigits=None) 經number變為浮點數,ndigits決定保留小數位數,預設為0
callable()返回bool,判斷引數是否為可呼叫物件
type() 輸出引數型別
isinstance(p\_object, class\_or\_type\_or_tuple) //返回bool,判斷引數是否為指定型別(可以將多個型別放在tuple中,只要屬於tuple中的型別就會返回True)
cmp() 判斷字元大小(應該是按ASCII碼排序),先比第一個然後,不比較字串長度
range(start=None, stop=None, step=None)
int() 資料型別轉換
float()
long()
complex()
str() 
list()
hex(number) ->str 把一個整數傳化成16進位制的字串
int()可以將其它進位制轉化為10進位制
oct(number) ->str 把一個整數轉化成8進位制的字串
eval(source, globals=None, locals=None) 將字串轉化有效表示式
chr() 返回ASCII碼對應字元
ord() 返回字元對應的ASCII碼
str.capitalisze() 字串的方法,將字串首字母大寫,若首字元不是字母,則會返回原字串
str.replace(self, old, new, count=None) \\\替換字串的字元
str.split(self, sep=None, maxsplit=None) \\\切分字串,預設按空格、tab(\\tb)、換行符(\\n)切分,返回列表;
str.join(iterable) 將可迭代物件的元素以指定字串連線,並返回字串

string 模組
string.lowercase
string.uppercase \\\列印大寫字母

filter(function_or_none, sequence)  \\按照function對後面的序列進行過濾,將後面的序列傳入前面的引數,如果返回True則返回序列元素

zip(seq1, seq2, *more_seqs) \\ 將多個序列合併為一個大的序列,序列長度不一致時會取最短的序列長度
	"""
	zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)]
	
	Return a list of tuples, where each tuple contains the i-th element
	from each of the argument sequences.  The returned list is truncated
	in length to the length of the shortest argument sequence.
	"""

map(function, sequence, *sequence_1) \\和zip類似,但會多一步對序列的元素按照function進行處理
	"""
	map(function, sequence[, sequence, ...]) -> list

	Return a list of the results of applying the function to the items of
	the argument sequence(s).  If more than one sequence is given, the
	function is called with an argument list consisting of the corresponding
	item of each sequence, substituting None for missing values when not all
	sequences have the same length.  If the function is None, return a list of
	the items of the sequence (or a list of tuples if more than one sequence).
	"""