python中的內建函式

2021-09-25 06:57:53 字數 2256 閱讀 8191

以下是目前我們已經滲透過的內建函式:

int()

建立或者將其他資料轉化為整型
float()

建立或者將其他資料轉化為浮點型
bool()

建立或者將其他資料轉化為布林型
complex()

建立或者將其他資料轉化為複數
str()

建立或者將其他資料轉化為字串
list()

建立或者將其他資料轉化為列表
tuple()

建立或者將其他資料轉化為元組
set()

建立或者將其他資料轉化為集合
dict()

建立或者將其他資料轉化為字典
以上函式可以用於建立或者進行型別轉換

id()

獲取變數的id標誌
type()

獲取變數的型別字串
print()

列印變數的值
locals()

列印當前環境中所有的變數
abs()

獲取乙個數值的絕對值
sum()

計算乙個序列的數值和
max()

獲取最大值

格式1:max(序列)

返回值:序列中的最大值

格式2:max(引數1,引數2...)

返回值:多個引數中的最大值

min()

獲取最小值

格式1:min(序列)

返回值:序列中的最小值

格式2:min(引數1,引數2...)

返回值:多個引數中的最小值

pow()

獲取乙個數值的n次方
round()

對乙個數值進行四捨五入操作
range()

產生連續資料的序列

格式1:range(結束值)

返回值:0-結束值之間的序列

格式2:range(開始值,結束值)

返回值:開始-結束值之間的序列

格式3:range(開始值,結束值,間隔值)

返回值:開始-結束值之間指定間隔的資料的序列

hex()

將十進位制轉化為16進製制
oct()

將十進位制轉化為8進製
bin()

將十進位制轉化為2進製字串相關:
chr()

將ascii編碼轉化為字元
ord()

將字元轉化為ascii編碼
repr()

獲取任意資料的原始格式字串
eval()

將乙個字串當作python**執行,字串需要符合**規範和repr配合

python 中的內建函式

built in functions abs divmod input open staticmethod all enumerate int ord str any eval isinstance pow sum basestring execfile issubclass print super...

Python中的內建函式

len s 返回物件內元素的個數。dic s lst 2 3,4 5,6 6 print len dic print len s print len lst 輸出結果 2 46max iterable,key,default 返回最大值。max 1 max 3,1,2,6 max 2 max def...

python中的內建函式

abs number 取絕對值1 re abs 342 2print re 3 輸出 342 all iterable 判斷可迭代的物件的元素是否都是真,如果是返回true 否則返回false 0,none,空 都是假li 12,43,23,re all li print re 輸出 true li...