python内蔵関数Built-in Functions

8370 ワード

python
pythonの組み込み関数の解釈と分類を試みます
組み込み関数の分類
はんしゃさぎょう
実行状態では、任意のクラスについて、このクラスのすべての属性と方法を知ることができます.任意のオブジェクトに対して、メソッドとプロパティを呼び出すことができます.__import__() __import__('sys').path isinstance() isinstance('abc', str) = True issubclass() issubclass(str, str) = True hasattr() hasattr(str, 'join') # ''.join([1, 2]) getattr() getattr(str, 'join') setattr() setattr(p, 'name', 'xiaoming') delattr() delattr(p, 'name') callable() callable(str) = True
変数アクションglobals() globals() locals() locals()
インタラクティブな操作print() print('123') input() p = input()
ファイルアクションopen() with open('/test.txt', 'rb') as f
コンパイル実行compile() AST , exec eval compile('1+2', '', 'eval') eval() eval('1+2+3+4') = 10 exec() exec('p=2+3') print(p) # 5 repr() ( ) repr(str)
デコレーションproperty() @property classmethod() @classmethod staticmethod() @staticmethod
シーケンスアクションall() False all([1, 2, 3, 0]) = False any() False any([0, 0, 0, 0, 1]) = True filter() list(filter(lambda p:p <3, [1, 2, 3])) = [1, 2] next() , next(iter([1, 2, 3])) = 1 map() list(map(lambda p:p**2, [1, 2, 3])) = [1, 4, 9] sorted() , key sorted(['2', '1', '3'], key=int, reverse=True) = ['3', '2', '1'] reversed() list(reversed(['2', '1', '3'])) = ['3', '1', '2'] zip() list(zip([1, 2, 3], [1, 2, 3])) = [(1, 1), (2, 2), (3, 3)]
オブジェクトアクションhelp() help(str) id() id('123') dir() dir(str) hash() hash('123') vars() vars() ascii() ascii('') = '\u7b80\u4e66' type() Person = type('Person', (), {'name':'python ~'}) p = Person() p.name len() len('123') = 3 format() format(123, 'b') = 1111011
数値計算abs() abs(-1) = 1 divmod() divmod(11,3) = 3( ),2( ) pow() pow(2, 3) = 2**3 = 8 max() max([(1, 2), (2, 3), (3, 1)], key=lambda p:p[1]) = (2,3) min() min([(1, 2), (2, 3), (3, 1)], key=lambda p:p[1]) = (3,1) sum() sum([1, 2, 3]) = 6 round() round(1.12345, 3) = 1.123 #
タイプ変換bool() bool bool('') = bool(0) = bool(False) = False bytearray() bytearray(' ', encoding='utf8') bytes() bytes(' ', encoding='utf8') float() float float(1) = 1.o int() int int(10.0) = int('10') = 10 hex() hex(10) = oxa oct() oct(16) = 0o20 bin() bin(8) = 0b1000 complex() complex('1+2j') = complex(1+2j) = (1+2j) chr() unicode chr(48) = 0 ord() unicode ord('0') = 48 str() str str(123) = '123' list() list list([1, 2, 3]) = [1, 2, 3] object() object obj = object() tuple() tuple tuple([1, 2, 3] = (1,2, 3) set() set set(range(3)) = {0, 1, 2} memoryview() memoryview(b'1234')[0] = 49 byte-like , unicode dict() dict dict({'0':0}) = {'0': 0} frozenset() frozenset([1, 2, 3]) = frozenset({1, 2, 3}) enumerate() enumerate([1, 2, 3, 4]) (index, item) range() range range(start, stop, step) iter() iter([1, 2, 3]).__next__() = 1 slice() list[slice(start, stop, step)] super() super().__init__()
Built-in Functions abs() dict() help() min() setattr() all() dir() hex() next() slice() any() divmod() id() object() sorted() ascii() enumerate() input() oct() staticmethod() bin() eval() int() open() str() bool() exec() isinstance() ord() sum() bytearray() filter() issubclass() pow() super() bytes() float() iter() print() tuple() callable() format() len() property() type() chr() frozenset() list() range() vars() classmethod() getattr() locals() repr() zip() compile() globals() map() reversed() __import__() complex() hasattr() max() round() delattr() hash() memoryview() set()