python內置函數是什么?一起來看下吧:
python內置函數有:
abs:求數值的絕對值
>>>abs(-2) 2
pmod:返回兩個數值的商和余數
>>>pmod(5,2) (2,1) >>pmod(5.5,2) (2.0,1.5)
bool:根據傳入的參數的邏輯值創建一個布爾值
>>>bool()?#未傳入參數 False >>>bool(0)?#數值0、空序列等值為False False >>>bool(1) True
all:判斷可迭代對象的每個元素是否都為True值
>>>all([1,2])?#列表中每個元素邏輯值均為True,返回True True >>>?all(())?#空元組 True >>>?all({})?#空字典 True
help:返回對象的幫助信息
>>>?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_:動態導入模塊
index?=?__import__('index') index.sayHello()
locals:返回當前作用域內的局部變量和其值組成的字典
>>>?def?f(): ????print('before?define?a?') ????print(locals())?#作用域內無變量 ????a?=?1 ????print('after?define?a') ????print(locals())?#作用域內有一個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:使用指定的模式和編碼打開文件,返回文件讀寫對象
#?t為文本讀寫,b為二進制讀寫 >>>?a?=?open('test.txt','rt') >>>?a.read() 'some?text' >>>?a.close()
eval:執行動態表達式求值
>>>?eval('1+2+3+4') 10
除了上述舉例的函數之外,內置函數按分類還可分為:
1、數學運算(7個)
2、類型轉換(24個)
3、序列操作(8個)
4、對象操作(7個)
5、反射操作(8個)
6、變量操作(2個)
7、交互操作(2個)
8、文件操作(1個)
9、編譯操作(4個)
10、裝飾器(3個)
以上就是小編今天的分享,希望可以幫助到大家。