python 中的內建函式

2021-08-27 22:21:26 字數 2408 閱讀 2522

built-in functions

abs()

divmod()

input()

open()

staticmethod()

all()

enumerate()

int()

ord()

str()

any()

eval()

isinstance()

pow()

sum()

basestring()

execfile()

issubclass()

print()

super()

bin()

file()

iter()

property()

tuple()

bool()

filter()

len()

range()

type()

bytearray()

float()

list()

raw_input()

unichr()

callable()

format()

locals()

reduce()

unicode()

chr()

frozenset()

long()

reload()

vars()

classmethod()

getattr()

map()

repr()

xrange()

cmp()

globals()

max()

reversed()

zip()

compile()

hasattr()

memoryview()

round()

__import__()

complex()

hash()

min()

set()

delattr()

help()

next()

setattr()

buffer()

dict()

hex()

object()

slice()

coerce()

dir()

id()

oct()

sorted()

intern()

內建方法

說明__init__(self,...)

初始化物件,在建立新物件時呼叫

__del__(self)

釋放物件,在物件被刪除之前呼叫

__new__(cls,*args,**kwd)

例項的生成操作

__str__(self)

在使用print語句時被呼叫

__getitem__(self,key)

獲取序列的索引key對應的值,等價於seq[key]

__len__(self)

在呼叫內聯函式len()時被呼叫

__cmp__(stc,dst)

比較兩個物件src和dst

__getattr__(s,name)

獲取屬性的值

__setattr__(s,name,value)

設定屬性的值

__delattr__(s,name)

刪除name屬性

__getattribute__()

__getattribute__()功能與__getattr__()類似

__gt__(self,other)

判斷self物件是否大於other物件

__lt__(slef,other)

判斷self物件是否小於other物件

__ge__(slef,other)

判斷self物件是否大於或者等於other物件

__le__(slef,other)

判斷self物件是否小於或者等於other物件

__eq__(slef,other)

判斷self物件是否等於other物件

__call__(self,*args)

把例項物件作為函式呼叫

python中的內建函式

以下是目前我們已經滲透過的內建函式 int 建立或者將其他資料轉化為整型float 建立或者將其他資料轉化為浮點型bool 建立或者將其他資料轉化為布林型complex 建立或者將其他資料轉化為複數str 建立或者將其他資料轉化為字串list 建立或者將其他資料轉化為列表tuple 建立或者將其他資...

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...