python的內置函數
『壹』 python裡面有哪些自帶函數
python系統提供了下面常用的函數:
1. 數學庫模塊(math)提供了很多數學運算函數;
2.復數模塊(cmath)提供了用於復數運算的函數;
3.隨機數模塊(random)提供了用來生成隨機數的函數;
4.時間(time)和日歷(calendar)模塊提供了能處理日期和時間的函數。
注意:在調用系統函數之前,先要使用import 語句導入 相應的模塊
該語句將模塊中定義的函數代碼復制到自己的程 序中,然後就可以訪問模塊中的任何函數,其方 法是在函數名前面加上「模塊名.」。
希望能幫到你。
『貳』 python內置函數
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 mole 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個)
『叄』 python語言中可以調用的函數有哪些
Python語言中有碰鋒很多內置函數和標准庫函數可以直接調用,同時還可以自定義函數和調用其他模塊中的函數。以下是一些常用的Python內置函數和標准庫函數:
- 數學函數:abs(), pow(), round(), max(), min(), math庫中的sin(), cos(), tan(), pi等函數。
- 字元串函遲腔數:len(), str(), int(), float(), ord(), chr(), upper(), lower(), replace(), split()等函數。
- 列表函數:append(), extend(), insert(), remove(), pop(), sort(), reverse()等函數。
- 文件操作函數:open(), read(), write(), close()等函數。
- 時間和日期函數:time(), sleep(), strftime()等函數。
- 正則表達式函數:re.compile(), re.search(), re.match(), re.sub()等函數。
- 網路編程函數:socket庫中笑旦晌的socket(), bind(), listen(), accept()等函數。