python內(nèi)置函數(shù)是什么?一起來(lái)看下吧:
python內(nèi)置函數(shù)有:
abs:求數(shù)值的絕對(duì)值
>>>abs(-2) 2
pmod:返回兩個(gè)數(shù)值的商和余數(shù)
>>>pmod(5,2) (2,1) >>pmod(5.5,2) (2.0,1.5)
bool:根據(jù)傳入的參數(shù)的邏輯值創(chuàng)建一個(gè)布爾值
>>>bool()?#未傳入?yún)?shù) False >>>bool(0)?#數(shù)值0、空序列等值為False False >>>bool(1) True
all:判斷可迭代對(duì)象的每個(gè)元素是否都為T(mén)rue值
>>>all([1,2])?#列表中每個(gè)元素邏輯值均為T(mén)rue,返回True True >>>?all(())?#空元組 True >>>?all({})?#空字典 True
help:返回對(duì)象的幫助信息
>>>?help(str)? Help?on?class?str?in?module?builtins: class?str(object) |??str(object='')?->?str |??str(bytes_or_buffer[,?encoding[,?errors]])?->?str |?? |??Create?a?new?string?object?from?the?given?object.?If?encoding?or |??errors?is?specified,?then?the?object?must?expose?a?data?buffer |??that?will?be?decoded?using?the?given?encoding?and?error?handler. |??Otherwise,?returns?the?result?of?object.__str__()?(if?defined) |??or?repr(object). |??encoding?defaults?to?sys.getdefaultencoding(). |??errors?defaults?to?'strict'. |?? |??Methods?defined?here: |?? |??__add__(self,?value,?/) ??????????Return?self+value.
_import_:動(dòng)態(tài)導(dǎo)入模塊
index?=?__import__('index') index.sayHello()
locals:返回當(dāng)前作用域內(nèi)的局部變量和其值組成的字典
>>>?def?f(): ????print('before?define?a?') ????print(locals())?#作用域內(nèi)無(wú)變量 ????a?=?1 ????print('after?define?a') ????print(locals())?#作用域內(nèi)有一個(gè)a變量,值為1 >>>?f>>>?f() before?define?a? {}? after?define?a {'a':?1}
input:讀取用戶輸入值
>>>?s?=?input('please?input?your?name:') please?input?your?name:Ain >>>?s 'Ain'
open:使用指定的模式和編碼打開(kāi)文件,返回文件讀寫(xiě)對(duì)象
#?t為文本讀寫(xiě),b為二進(jìn)制讀寫(xiě) >>>?a?=?open('test.txt','rt') >>>?a.read() 'some?text' >>>?a.close()
eval:執(zhí)行動(dòng)態(tài)表達(dá)式求值
>>>?eval('1+2+3+4') 10
除了上述舉例的函數(shù)之外,內(nèi)置函數(shù)按分類還可分為:
1、數(shù)學(xué)運(yùn)算(7個(gè))
2、類型轉(zhuǎn)換(24個(gè))
3、序列操作(8個(gè))
4、對(duì)象操作(7個(gè))
5、反射操作(8個(gè))
6、變量操作(2個(gè))
7、交互操作(2個(gè))
8、文件操作(1個(gè))
9、編譯操作(4個(gè))
10、裝飾器(3個(gè))
以上就是小編今天的分享,希望可以幫助到大家。