Built-in functions — Dokumentasi Python 3.15.2
Navigasi index modul | berikut | sebelum | Python » 3.15.2 documentation » Python built-ins reference » Built-in functions | Tema | Built-in functions ¶ Interpreter Python memiliki sejumlah fungsi dan tipe bawaan di dalamnya yang selalu tersedia. Mereka terdaftar di sini dalam urutan abjad. Fungsi Bawaan A abs() aiter() all() anext() any() ascii() B bin() bool() breakpoint() bytearray() bytes() C callable() chr() classmethod() compile() complex() D delattr() dict() dir() divmod() E enumerate() eval() exec() F filter() float() format() frozendict() frozenset() G getattr() globals() H hasattr() hash() help() hex() I id() input() int() isinstance() issubclass() iter() L len() list() locals() M map() max() memoryview() min() N next() O object() oct() open() ord() P pow() print() property() R range() repr() reversed() round() S set() setattr() sentinel() slice() sorted() staticmethod() str() sum() super() T tuple() type() V vars() Z zip() _ __import__() abs ( number , / ) ¶ Return the absolute value of a number.
The argument may be an integer, a floating-point number, or an object implementing __abs__() . If the argument is a complex number, its magnitude is returned. aiter ( async_iterable , / ) ¶ Return an asynchronous iterator for an asynchronous iterable . Equivalent to calling x.__aiter__() . Note: Unlike iter() , aiter() has no 2-argument variant. Added in version 3.10. all ( iterable , / ) ¶ Kembalikan True jika semua elemen dari iterable bernilai benar (atau jika iterable kosong).
Setara dengan: def all ( iterable ): for element in iterable : if not element : return False return True awaitable anext ( async_iterator , / ) ¶ awaitable anext ( async_iterator , default , / ) When awaited, return the next item from the given asynchronous iterator , or default if given and the iterator is exhausted . This is the async variant of the next() builtin, and behaves similarly. This calls the __anext__() method of async_iterator , returning an awaitable .
Awaiting this returns the next value of the iterator. If default is given, it is returned if the iterator is exhausted, otherwise StopAsyncIteration is raised. Added in version 3.10. any ( iterable , / ) ¶ Kembalikan True jika ada elemen dari iterable bernilai benar. Jika iterable kosong, kembalikan False . Setara dengan: def any ( iterable ): for element in iterable : if element : return True return False ascii ( object , / ) ¶ As repr() , return a string containing a printable representation of an object, but escape the non-ASCII characters in the string returned by repr() using \x , \u , or \U escapes.
This generates a string similar to that returned by repr() in Python 2. bin ( integer , / ) ¶ Convert an integer number to a binary string prefixed with "0b". The result is a valid Python expression. If integer is not a Python int object, it has to define an __index__() method that returns an integer. Some examples: >>> bin ( 3 ) '0b11' >>> bin ( - 10 ) '-0b1010' If the prefix "0b" is desired or not, you can use either of the following ways. >>> format ( 14 , '#b' ), format ( 14 , 'b' ) ('0b1110', '1110') >>> f ' { 14 : #b } ' , f ' { 14 : b } ' ('0b1110', '1110') See also enum.bin() to represent negative values as twos-complement.
Lihat juga format() untuk informasi lebih lanjut. class bool ( object = False , / ) ¶ Return a Boolean value, i.e. one of True or False . The argument is converted using the standard truth testing procedure . If the argument is false or omitted, this returns False ; otherwise, it returns True . The bool class is a subclass of int (see Numeric Types --- int, float, complex ). It cannot be subclassed further. Its only instances are False and True (see Boolean Type - bool ).
Berubah pada versi 3.7: The parameter is now positional-only. breakpoint ( * args , ** kws ) ¶ This function drops you into the debugger at the call site. Specifically, it calls sys.breakpointhook() , passing args and kws straight through. By default, sys.breakpointhook() calls pdb.set_trace() expecting no arguments. In this case, it is purely a convenience function so you don't have to explicitly import pdb or type as much code to enter the debugger.
However, sys.breakpointhook() can be set to some other function and breakpoint() will automatically call that, allowing you to drop into the debugger of choice. If sys.breakpointhook() is not accessible, this function will raise RuntimeError . By default, the behavior of breakpoint() can be changed with the PYTHONBREAKPOINT environment variable. See sys.breakpointhook() for usage details. Note that this is not guaranteed if sys.breakpointhook() has been replaced.
Memunculkan auditing event builtins.breakpoint dengan argumen breakpointhook . Added in version 3.7. class bytearray ( source = b'' ) class bytearray ( source , encoding , errors = 'strict' ) Kembalikan array byte baru. Kelas bytearray adalah urutan bilangan bulat yang dapat berubah dalam kisaran 0 <= x <256. Ia memiliki sebagian besar metode urutan-urutan yang dapat berubah, yang dijelaskan dalam Mutable Sequence Types , dan juga sebagian besar metode yang dimiliki oleh bytes , lihat Bytes and Bytearray Operations .
Parameter opsional source dapat digunakan untuk menginisialisasi array dengan beberapa cara berbeda: Jika ini adalah string , Anda juga harus memberikan parameter encoding (dan opsional, errors ); bytearray() kemudian mengonversi string menjadi byte menggunakan str.encode() . Jika ini adalah integer , array akan memiliki ukuran itu dan akan diinisialisasi dengan null bytes . Jika itu adalah objek yang sesuai dengan buffer interface , buffer yang hanya baca dari objek tersebut akan digunakan untuk menginisialisasi array byte.
Jika ini adalah iterable , itu harus iterable dari bilangan bulat dalam kisaran 0 <= x < 256 , yang digunakan sebagai konten awal array. Tanpa argumen, dibuat array berukuran 0. Lihat juga Binary Sequence Types --- bytes, bytearray, memoryview dan Bytearray Objects . class bytes ( source = b'' ) class bytes ( source , encoding , errors = 'strict' ) Return a new "bytes" object which is an immutable sequence of integers in the range 0 <= x < 256 . bytes is an immutable version of bytearray -- it has the same non-mutating methods and the same indexing and slicing behavior.
Dengan demikian, argumen konstruktor ditafsirkan untuk bytearray() . Objek byte juga dapat dibuat dengan literal, lihat String and Bytes literals . Lihat juga Binary Sequence Types --- bytes, bytearray, memoryview , Bayt Nesneleri , dan Bytes and Bytearray Operations . callable ( object , / ) ¶ Return True if the object argument appears callable, False if not. If this returns True , it is still possible that a call fails, but if it is False , calling object will never succeed.
Note that classes are callable (calling a class returns a new instance); instances are callable if their class has a __call__() method. Added in version 3.2: Fungsi ini pertama kali dihapus di Python 3.0 dan kemudian dibawa kembali di Python 3.2. chr ( codepoint , / ) ¶ Return the string representing a character with the specified Unicode code point. For example, chr(97) returns the string 'a' , while chr(8364) returns the string '€' .
This is the inverse of ord() . The valid range for the argument is from 0 through 1,114,111 (0x10FFFF in base 16). ValueError will be raised if it is outside that range. @ classmethod ¶ Ubah metode menjadi metode kelas. A class method receives the class as an implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom: class C : @classmethod def f ( cls , arg1 , arg2 ): ...
Bentuk @classmethod adalah fungsi decorator -- lihat Definisi fungsi untuk detail. Metode kelas dapat dipanggil baik pada kelas (seperti C.f() ) atau pada instance (seperti C().f() ). Instance diabaikan kecuali untuk kelasnya. Jika metode kelas dipanggil untuk kelas turunan, objek kelas turunan dilewatkan sebagai argumen pertama yang tersirat. Class method
The rest of this page is on the live site.