Teks sumber — English
Terjemahan — Bahasa Indonesia
Return the absolute value of a number. The argument may be an integer, a floating-point number, or an object implementing :meth:`~object.__abs__`. If the argument is a complex number, its magnitude is returned.
Return an :term:`asynchronous iterator` for an :term:`asynchronous iterable`. Equivalent to calling ``x.__aiter__()``.
Return ``True`` if all elements of the *iterable* are true (or if the iterable is empty). Equivalent to::
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
When awaited, return the next item from the given :term:`asynchronous iterator`, or *default* if given and the iterator is :term:`exhausted`.
This calls the :meth:`~object.__anext__` method of *async_iterator*, returning an :term:`awaitable`. Awaiting this returns the next value of the iterator. If *default* is given, it is returned if the iterator is exhausted, otherwise :exc:`StopAsyncIteration` is raised.
Return ``True`` if any element of the *iterable* is true. If the iterable is empty, return ``False``. Equivalent to::
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
As :func:`repr`, return a string containing a printable representation of an object, but escape the non-ASCII characters in the string returned by :func:`repr` using ``\x``, ``\u``, or ``\U`` escapes. This generates a string similar to that returned by :func:`repr` in Python 2.
Convert an integer number to a binary string prefixed with "0b". The result is a valid Python expression. If *integer* is not a Python :class:`int` object, it has to define an :meth:`~object.__index__` method that returns an integer. Some examples:
Return a Boolean value, i.e. one of ``True`` or ``False``. The argument is converted using the standard :ref:`truth testing procedure <truth>`. If the argument is false or omitted, this returns ``False``; otherwise, it returns ``True``. The :class:`bool` class is a subclass of :class:`int` (see :ref:`typesnumeric`). It cannot be subclassed further. Its only instances are ``False`` and ``True`` (see :ref:`typebool`).
Return a new array of bytes. The :class:`bytearray` class is a mutable sequence of integers in the range 0 <= x < 256. It has most of the usual methods of mutable sequences, described in :ref:`typesseq-mutable`, as well as most methods that the :class:`bytes` type has, see :ref:`bytes-methods`.
Kembalikan array byte baru. Kelas :class:`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 :ref:`typesseq-mutable`, dan juga sebagian besar metode yang dimiliki oleh :class:`bytes`, lihat :ref:`bytes-methods`.
Return a new "bytes" object which is an immutable sequence of integers in the range ``0 <= x < 256``. :class:`bytes` is an immutable version of :class:`bytearray` -- it has the same non-mutating methods and the same indexing and slicing behavior.
Return :const:`True` if the *object* argument appears callable, :const:`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 :meth:`~object.__call__` method.
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 :func:`ord`.
If two arguments are provided or keyword arguments are used, each argument may be any numeric type (including complex). If both arguments are real numbers, return a complex number with the real component *real* and the imaginary component *imag*. If both arguments are complex numbers, return a complex number with the real component ``real.real-imag.imag`` and the imaginary component ``real.imag+imag.real``. If one of arguments is a real number, only its real component is used in the above expressions.
If all arguments are omitted, returns ``0j``.
Without arguments, return the list of names in the current local scope. With an argument, attempt to return a list of valid attributes for that object.
Tanpa argumen, kembalikan daftar *list* nama dalam lingkup lokal saat ini. Dengan argumen, mencoba untuk mengembalikan daftar *list* atribut yang valid untuk objek itu.
If the object has a method named :meth:`~object.__dir__`, this method will be called and must return the list of attributes. This allows objects that implement a custom :func:`~object.__getattr__` or :func:`~object.__getattribute__` function to customize the way :func:`dir` reports their attributes.
Take two (non-complex) numbers as arguments and return a pair of numbers consisting of their quotient and remainder when using integer division. With mixed operand types, the rules for binary arithmetic operators apply. For integers, the result is the same as ``(a // b, a % b)``. For floating-point numbers the result is ``(q, a % b)``, where *q* is usually ``math.floor(a / b)`` but may be 1 less than that. In any case ``q * b + a % b`` is very close to *a*, if ``a % b`` is non-zero it has the same sign as *b*, and ``0 <= abs(a % b) < abs(b)``.
Return an enumerate object. *iterable* must be a sequence, an :term:`iterator`, or some other object which supports iteration. The :meth:`~iterator.__next__` method of the iterator returned by :func:`enumerate` returns a tuple containing a count (from *start* which defaults to 0) and the values obtained from iterating over *iterable*.
Kembalikan objek enumerasi. *iterable* harus berupa urutan, sebuah :term:`iterator`, atau objek lain yang mendukung iterasi. The :meth:`~iterator.__next__` metode iterator dikembalikan oleh :func:`enumerate` mengembalikan tuple yang berisi hitungan (dari *start* yang bawaan ke 0) dan nilai yang diperoleh dari mengelilingi *iterable*.
Returns
Kembalian
This function can also be used to execute arbitrary code objects (such as those created by :func:`compile`). In this case, pass a code object instead of a string. If the code object has been compiled with ``'exec'`` as the *mode* argument, :func:`eval`\'s return value will be ``None``.
Hints: dynamic execution of statements is supported by the :func:`exec` function. The :func:`globals` and :func:`locals` functions return the current global and local dictionary, respectively, which may be useful to pass around for use by :func:`eval` or :func:`exec`.
This function supports dynamic execution of Python code. *source* must be either a string or a code object. If it is a string, the string is parsed as a suite of Python statements which is then executed (unless a syntax error occurs). If it is a code object, it is simply executed. In all cases, the code that's executed is expected to be valid as file input (see the section :ref:`file-input` in the Reference Manual). Be aware that the :keyword:`nonlocal`, :keyword:`yield`, and :keyword:`return` statements may not be used outside of function definitions even within the context of code passed to the :func:`exec` function. The return value is ``None``.
The built-in functions :func:`globals` and :func:`locals` return the current global and local namespace, respectively, which may be useful to pass around for use as the second and third argument to :func:`exec`.
The default *locals* act as described for function :func:`locals` below. Pass an explicit *locals* dictionary if you need to see effects of the code on *locals* after function :func:`exec` returns.
See :func:`itertools.filterfalse` for the complementary function that returns elements of *iterable* for which *function* is false.
Return a floating-point number constructed from a number or a string.
Otherwise, if the argument is an integer or a floating-point number, a floating-point number with the same value (within Python's floating-point precision) is returned. If the argument is outside the range of a Python float, an :exc:`OverflowError` will be raised.
If no argument is given, ``0.0`` is returned.
Jika tidak ada argumen yang diberikan, dikembalikan sebagai ``0.0``.
A call to ``format(value, format_spec)`` is translated to ``type(value).__format__(value, format_spec)`` which bypasses the instance dictionary when searching for the value's :meth:`~object.__format__` method. A :exc:`TypeError` exception is raised if the method search reaches :mod:`object` and the *format_spec* is non-empty, or if either the *format_spec* or the return value are not strings.
Return a new :class:`frozenset` object, optionally with elements taken from *iterable*. :class:`frozenset` is a built-in class. See also :ref:`types-set` for documentation about this class.
Return the value of the named attribute of *object*. *name* must be a string. If the string is the name of one of the object's attributes, the result is the value of that attribute. For example, ``getattr(x, 'foobar')`` is equivalent to ``x.foobar``. If the named attribute does not exist, *default* is returned if provided, otherwise :exc:`AttributeError` is raised. *name* need not be a Python identifier (see :func:`setattr`).
Return the dictionary implementing the current module namespace. For code within functions, this is set when the function is defined and remains the same regardless of where the function is called.
Return the hash value of the object (if it has one). Hash values are integers. They are used to quickly compare dictionary keys during a dictionary lookup. Numeric values that compare equal have the same hash value (even if they are of different types, as is the case for 1 and 1.0).
Kembalikan nilai hash objek (jika ada). Nilai hash adalah bilangan bulat. Mereka digunakan untuk dengan cepat membandingkan kunci kamus *dictionary keys* selama pencarian dictionary. Nilai numerik yang membandingkan sama memiliki nilai hash yang sama (bahkan jika mereka dari jenis yang berbeda, seperti halnya untuk 1 dan 1.0).
For objects with custom :meth:`~object.__hash__` methods, note that :func:`hash` truncates the return value based on the bit width of the host machine.
Convert an integer number to a lowercase hexadecimal string prefixed with "0x". If *integer* is not a Python :class:`int` object, it has to define an :meth:`~object.__index__` method that returns an integer. Some examples:
Return the "identity" of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same :func:`id` value.
Kembalikan "identity" suatu objek. Ini adalah bilangan bulat yang dijamin unik dan konstan untuk objek ini selama masa pakainya. Dua objek dengan masa hidup yang tidak tumpang tindih mungkin memiliki nilai yang sama :func:`id`.
If the *prompt* argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, :exc:`EOFError` is raised. Example::
Jika argumen *prompt* ada, ini ditulis ke keluaran standar tanpa baris tambahan. Fungsi ini kemudian membaca sebuah baris dari masukan, mengubahnya menjadi sebuah string (menghapus baris baru yang tertinggal), dan mengembalikannya. Ketika EOF dibaca, :exc:`EOFError` dimunculkan. Contoh::
Return an integer object constructed from a number or a string, or return ``0`` if no arguments are given.
If the argument defines :meth:`~object.__int__`, ``int(x)`` returns ``x.__int__()``. If the argument defines :meth:`~object.__index__`, it returns ``x.__index__()``. For floating-point numbers, this truncates towards zero.
Return ``True`` if the *object* argument is an instance of the *classinfo* argument, or of a (direct, indirect, or :term:`virtual <abstract base class>`) subclass thereof. If *object* is not an object of the given type, the function always returns ``False``. If *classinfo* is a tuple of type objects (or recursively, other such tuples) or a :ref:`types-union` of multiple types, return ``True`` if *object* is an instance of any of the types. If *classinfo* is not a type or tuple of types and such tuples, a :exc:`TypeError` exception is raised. :exc:`TypeError` may not be raised for an invalid type if an earlier check succeeds.
Return ``True`` if *cls* is a subclass (direct, indirect, or :term:`virtual <abstract base class>`) of *classinfo*. A class is considered a subclass of itself. *classinfo* may be a tuple of class objects (or recursively, other such tuples) or a :ref:`types-union`, in which case return ``True`` if *cls* is a subclass of any entry in *classinfo*. In any other case, a :exc:`TypeError` exception is raised.
Return an :term:`iterator` object. The first argument is interpreted very differently depending on the presence of the second argument. Without a second argument, the single argument must be a collection object which supports the :term:`iterable` protocol (the :meth:`~object.__iter__` method), or it must support the sequence protocol (the :meth:`~object.__getitem__` method with integer arguments starting at ``0``). If it does not support either of those protocols, :exc:`TypeError` is raised. If the second argument, *sentinel*, is given, then the first argument must be a callable object. The iterator created in this case will call *callable* with no arguments for each call to its :meth:`~iterator.__next__` method; if the value returned is equal to *sentinel*, :exc:`StopIteration` will be raised, otherwise the value will be returned.
Return the length (the number of items) of an object. The argument may be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set).
Mengembalikan panjang (jumlah item) suatu objek. Argumennya bisa berupa urutan (seperti string, byte, *tuple*, *list*, atau *range*) atau koleksi (seperti *dictionary*, set, atau *frozen set*).
Return a mapping object representing the current local symbol table, with variable names as the keys, and their currently bound references as the values.
At module scope, as well as when using :func:`exec` or :func:`eval` with a single namespace, this function returns the same namespace as :func:`globals`.
At class scope, it returns the namespace that will be passed to the metaclass constructor.
When using ``exec()`` or ``eval()`` with separate local and global arguments, it returns the local namespace passed in to the function call.
In all of the above cases, each call to ``locals()`` in a given frame of execution will return the *same* mapping object. Changes made through the mapping object returned from ``locals()`` will be visible as assigned, reassigned, or deleted local variables, and assigning, reassigning, or deleting local variables will immediately affect the contents of the returned mapping object.
In an :term:`optimized scope` (including functions, generators, and coroutines), each call to ``locals()`` instead returns a fresh dictionary containing the current bindings of the function's local variables and any nonlocal cell references. In this case, name binding changes made via the returned dict are *not* written back to the corresponding local variables or nonlocal cell references, and assigning, reassigning, or deleting local variables and nonlocal cell references does *not* affect the contents of previously returned dictionaries.
As part of :pep:`667`, the semantics of mutating the mapping objects returned from this function are now defined. The behavior in :term:`optimized scopes <optimized scope>` is now as described above. Aside from being defined, the behaviour in other scopes remains unchanged from previous versions.
Return an iterator that applies *function* to every item of *iterable*, yielding the results. If additional *iterables* arguments are passed, *function* must take that many arguments and is applied to the items from all iterables in parallel. With multiple iterables, the iterator stops when the shortest iterable is :term:`exhausted`. If *strict* is ``True`` and one of the iterables is exhausted before the others, a :exc:`ValueError` is raised. For cases where the function inputs are already arranged into argument tuples, see :func:`itertools.starmap`.
Return the largest item in an iterable or the largest of two or more arguments.
Kembalikan item terbesar dalam iterable atau yang terbesar dari dua atau lebih argumen.
If one positional argument is provided, it should be an :term:`iterable`. The largest item in the iterable is returned. If two or more positional arguments are provided, the largest of the positional arguments is returned.
Jika satu argumen posisi disediakan, itu harus berupa :term:`iterable`. Item terbesar di *iterable* dikembalikan. Jika dua atau lebih argumen posisi disediakan, argumen posisi terbesar dikembalikan.
There are two optional keyword-only arguments. The *key* argument specifies a one-argument ordering function like that used for :meth:`list.sort`. The *default* argument specifies an object to return if the provided iterable is empty. If the iterable is empty and *default* is not provided, a :exc:`ValueError` is raised.
Ada dua opsional hanya argumen kata kunci *keyword arguments*. Argumen *key* menentukan fungsi pengurutan satu argumen seperti yang digunakan untuk :meth:`list.sort`. Argumen *default* menentukan objek yang akan dikembalikan jika yang disediakan itu kosong. Jika iterable kosong dan *default* tidak disediakan, :exc:`ValueError` akan dimunculkan.
If multiple items are maximal, the function returns the first one encountered. This is consistent with other sort-stability preserving tools such as ``sorted(iterable, key=keyfunc, reverse=True)[0]`` and ``heapq.nlargest(1, iterable, key=keyfunc)``.
Jika beberapa item maksimal, fungsi mengembalikan item pertama yang ditemui. Ini konsisten dengan alat pengawet *preserving* sortir yang stabil lain seperti ``sorted(iterable, key=keyfunc, reverse=True)[0]`` dan ``heapq.nlargest(1, iterable, key=keyfunc)``.
Return a "memory view" object created from the given argument. See :ref:`typememoryview` for more information.
Kembalikan objek "memory view" yang dibuat dari argumen yang diberikan. Lihat :ref:`typememoryview` untuk informasi lebih lanjut.
Return the smallest item in an iterable or the smallest of two or more arguments.
Kembalikan item terkecil dalam *iterable* atau terkecil dari dua atau lebih argumen.
If one positional argument is provided, it should be an :term:`iterable`. The smallest item in the iterable is returned. If two or more positional arguments are provided, the smallest of the positional arguments is returned.
Jika satu argumen posisi disediakan, itu harus berupa :term:`iterable`. Item terkecil di *iterable* dikembalikan. Jika dua atau lebih argumen posisional disediakan, argumen posisional terkecil akan dikembalikan.
If multiple items are minimal, the function returns the first one encountered. This is consistent with other sort-stability preserving tools such as ``sorted(iterable, key=keyfunc)[0]`` and ``heapq.nsmallest(1, iterable, key=keyfunc)``.
Jika beberapa item minimal, fungsi mengembalikan item pertama yang ditemui. Ini konsisten dengan alat pengawet *preserving* sortir yang stabil lain seperti ``sorted(iterable, key=keyfunc)[0]`` dan ``heapq.nsmallest(1, iterable, key=keyfunc)``.
Retrieve the next item from the :term:`iterator` by calling its :meth:`~iterator.__next__` method. If *default* is given, it is returned if the iterator is :term:`exhausted`, otherwise :exc:`StopIteration` is raised.
This is the ultimate base class of all other classes. It has methods that are common to all instances of Python classes. When the constructor is called, it returns a new featureless object. The constructor does not accept any arguments.
Convert an integer number to an octal string prefixed with "0o". The result is a valid Python expression. If *integer* is not a Python :class:`int` object, it has to define an :meth:`~object.__index__` method that returns an integer. For example:
Open *file* and return a corresponding :term:`file object`. If the file cannot be opened, an :exc:`OSError` is raised. See :ref:`tut-files` for more examples of how to use this function.
Buka *file* dan mengembalikan yang sesuai dengan :term:`file object`. Jika file tersebut tidak dapat dibuka, sebuah :exc:`OSError` akan dinaikkan. Lihat :ref:`tut-files` untuk contoh yang lebih banyak terkait bagaimana menggunakan fungsi ini.
*file* is a :term:`path-like object` giving the pathname (absolute or relative to the current working directory) of the file to be opened or an integer file descriptor of the file to be wrapped. (If a file descriptor is given, it is closed when the returned I/O object is closed unless *closefd* is set to ``False``.)
As mentioned in the :ref:`io-overview`, Python distinguishes between binary and text I/O. Files opened in binary mode (including ``'b'`` in the *mode* argument) return contents as :class:`bytes` objects without any decoding. In text mode (the default, or when ``'t'`` is included in the *mode* argument), the contents of the file are returned as :class:`str`, the bytes having been first decoded using the default encoding or using the specified *encoding* if given.
"Interactive" text files (files for which :meth:`~io.IOBase.isatty` returns ``True``) use line buffering. Other text files use the policy described above for binary files.
Berkas teks "interactive" (berkas yang :meth:`~io.IOBase.isatty` mengembalikan ``True``) menggunakan *line buffering*. File teks lainnya menggunakan kebijakan yang dijelaskan di atas untuk file biner.
*encoding* is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is UTF-8; if :ref:`Python UTF-8 Mode <utf8-mode>` is disabled, the default is platform-dependent (whatever :func:`locale.getencoding` returns). Any :term:`text encoding` supported by Python can be used, and ``encoding="locale"`` specifies the current locale encoding explicitly. See the :mod:`codecs` module for the list of supported encodings.
When reading input from the stream, if *newline* is ``None``, universal newlines mode is enabled. Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated into ``'\n'`` before being returned to the caller. If it is ``''``, universal newlines mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated.
Saat membaca masukan dari aliran *stream*, jika *newline* adalah ``None``, mode universal baris baru diaktifkan. Baris dalam masukan dapat diakhiri dengan ``'\n'``, ``'\r'``, atau ``'\r\n'``, dan ini diterjemahkan ke dalam ``'\n'`` sebelum dikembalikan ke pemanggil. Jika ``''``, mode baris baru universal diaktifkan, tetapi akhir baris dikembalikan ke pemanggil yang tidak diterjemahkan. Jika memiliki salah satu nilai legal lainnya, jalur masukan hanya diakhiri oleh string yang diberikan, dan akhir baris dikembalikan ke pemanggil yang tidak diterjemahkan.
A custom opener can be used by passing a callable as *opener*. The underlying file descriptor for the file object is then obtained by calling *opener* with (*file*, *flags*). *opener* must return an open file descriptor (passing :mod:`os.open` as *opener* results in functionality similar to passing ``None``).
Pembuka khusus dapat digunakan dengan melewatkan *callable* sebagai *opener*. Deskriptor berkas yang mendasari untuk objek berkas kemudian diperoleh dengan memanggil *opener* dengan (*file*, *flags*). *opener* harus mengembalikan deskriptor berkas terbuka (lewat :mod:`os.open` sebagai *opener* menghasilkan fungsionalitas yang mirip dengan melewatkan ``None``).
>>> import os
>>> dir_fd = os.open('somedir', os.O_RDONLY)
>>> def opener(path, flags):
... return os.open(path, flags, dir_fd=dir_fd)
...
>>> with open('spamspam.txt', 'w', opener=opener) as f:
... print('This will be written to somedir/spamspam.txt', file=f)
...
>>> os.close(dir_fd) # don't leak a file descriptor
The type of :term:`file object` returned by the :func:`open` function depends on the mode. When :func:`open` is used to open a file in a text mode (``'w'``, ``'r'``, ``'wt'``, ``'rt'``, etc.), it returns a subclass of :class:`io.TextIOBase` (specifically :class:`io.TextIOWrapper`). When used to open a file in a binary mode with buffering, the returned class is a subclass of :class:`io.BufferedIOBase`. The exact class varies: in read binary mode, it returns an :class:`io.BufferedReader`; in write binary and append binary modes, it returns an :class:`io.BufferedWriter`, and in read/write mode, it returns an :class:`io.BufferedRandom`. When buffering is disabled, the raw stream, a subclass of :class:`io.RawIOBase`, :class:`io.FileIO`, is returned.
Tipe :term:`file object` yang dikembalikan oleh fungsi :func:`open` tergantung pada mode. Ketika :func:`open` digunakan untuk membuka berkas dalam mode teks (``'w'``, ``'r'``, ``'wt'``, ``'rt'``, dll.), ia mengembalikan subkelas dari :class:`io.TextIOBase` (khusus :class:`io.TextIOWrapper`). Ketika digunakan untuk membuka file dalam mode biner dengan *buffering*, kelas yang dikembalikan adalah subkelas dari :class:`io.BufferedIOBase`. Kelas yang tepat bervariasi: dalam mode baca biner, ia mengembalikan :class:`io.BufferedReader`; dalam mode tulis biner dan *append* biner, ia mengembalikan sebuah :class:`io.BufferedWriter`, dan dalam mode baca/tulis, ia mengembalikan sebuah :class:`io.BufferedRandom`. Ketika *buffering* dinonaktifkan, aliran tak diproses *raw stream*, subkelas dari :class:`io.RawIOBase`, :class:`io.FileIO`, dikembalikan.
On Windows, opening a console buffer may return a subclass of :class:`io.RawIOBase` other than :class:`io.FileIO`.
Di Windows, membuka penyangga *buffer* konsol dapat mengembalikan subclass dari :class:`io.RawIOBase` selain :class:`io.FileIO`.
Return the ordinal value of a character.
If the argument is a one-character string, return the Unicode code point of that character. For example, ``ord('a')`` returns the integer ``97`` and ``ord('€')`` (Euro sign) returns ``8364``. This is the inverse of :func:`chr`.
If the argument is a :class:`bytes` or :class:`bytearray` object of length 1, return its single byte value. For example, ``ord(b'a')`` returns the integer ``97``.
Return *base* to the power *exp*; if *mod* is present, return *base* to the power *exp*, modulo *mod* (computed more efficiently than ``pow(base, exp) % mod``). The two-argument form ``pow(base, exp)`` is equivalent to using the power operator: ``base**exp``.
Kembalikan *base* ke *power* *exp*; jika *mod* ada, kembalikan *base* ke *power* *exp*, *modulo* *mod* (dihitung lebih efisien daripada ``pow(base, exp) % mod``). Bentuk dua argumen ``pow(base, exp)`` setara dengan menggunakan operator *power*: ``base**exp``.
When arguments are builtin numeric types with mixed operand types, the coercion rules for binary arithmetic operators apply. For :class:`int` operands, the result has the same type as the operands (after coercion) unless the second argument is negative; in that case, all arguments are converted to float and a float result is delivered. For example, ``pow(10, 2)`` returns ``100``, but ``pow(10, -2)`` returns ``0.01``. For a negative base of type :class:`int` or :class:`float` and a non-integral exponent, a complex result is delivered. For example, ``pow(-9, 0.5)`` returns a value close to ``3j``. Whereas, for a negative base of type :class:`int` or :class:`float` with an integral exponent, a float result is delivered. For example, ``pow(-9, 2.0)`` returns ``81.0``.
For :class:`int` operands *base* and *exp*, if *mod* is present, *mod* must also be of integer type and *mod* must be nonzero. If *mod* is present and *exp* is negative, *base* must be relatively prime to *mod*. In that case, ``pow(inv_base, -exp, mod)`` is returned, where *inv_base* is an inverse to *base* modulo *mod*.
Untuk operan :class:`int` *base* dan *exp*, jika *mod* ada, *mod* juga harus bertipe integer dan *mod* harus bukan nol. Jika *mod* ada dan *exp* negatif, *basis* harus relatif prima ke *mod*. Dalam kasus itu, ``pow(inv_base, -exp, mod)`` dikembalikan, di mana *inv_base* adalah kebalikan dari *base* *modulo* *mod*.
Return a property attribute.
Kembalikan atribut properti.
class C:
def __init__(self):
self._x = None
def getx(self):
return self._x
def setx(self, value):
self._x = value
def delx(self):
del self._x
x = property(getx, setx, delx, "I'm the 'x' property.")
class Parrot:
def __init__(self):
self._voltage = 100000
@property
def voltage(self):
"""Get the current voltage."""
return self._voltage
class C:
def __init__(self):
self._x = None
@property
def x(self):
"""I'm the 'x' property."""
return self._x
@x.setter
def x(self, value):
self._x = value
@x.deleter
def x(self):
del self._x
The returned property object also has the attributes ``fget``, ``fset``, and ``fdel`` corresponding to the constructor arguments.
Properti dari objek yang dikembalikan juga memiliki atribut ``fget``, ``fset``, dan ``fdel`` yang sesuai dengan argumen pembangun *constructor*.
Return a string containing a printable representation of an object. For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to :func:`eval`; otherwise, the representation is a string enclosed in angle brackets that contains the name of the type of the object together with additional information often including the name and address of the object. A class can control what this function returns for its instances by defining a :meth:`~object.__repr__` method.
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def __repr__(self):
return f"Person({self.name!r}, {self.age!r})"
Return a reverse :term:`iterator`. The argument must be an object which has a :meth:`~object.__reversed__` method or supports the sequence protocol (the :meth:`~object.__len__` method and the :meth:`~object.__getitem__` method with integer arguments starting at ``0``).
Return *number* rounded to *ndigits* precision after the decimal point. If *ndigits* is omitted or is ``None``, it returns the nearest integer to its input.
Kembalikan *number* dibulatkan ke *ndigits* presisi setelah titik desimal. Jika *ndigits* dihilangkan atau ``None``, ini akan mengembalikan integer terdekat ke masukannya.
For the built-in types supporting :func:`round`, values are rounded to the closest multiple of 10 to the power minus *ndigits*; if two multiples are equally close, rounding is done toward the even choice (so, for example, both ``round(0.5)`` and ``round(-0.5)`` are ``0``, and ``round(1.5)`` is ``2``). Any integer value is valid for *ndigits* (positive, zero, or negative). The return value is an integer if *ndigits* is omitted or ``None``. Otherwise, the return value has the same type as *number*.
Return a new :class:`set` object, optionally with elements taken from *iterable*. :class:`set` is a built-in class. See also :ref:`types-set` for documentation about this class.
Return a new unique sentinel object. *name* must be a :class:`str`, and is used by default as the returned object's representation::
Shallow and deep copies of a sentinel object return the object itself.
Return a :term:`slice` object representing the set of indices specified by ``range(start, stop, step)``. The *start* and *step* arguments default to ``None``.
See :func:`itertools.islice` for an alternate version that returns an :term:`iterator`.
Return a new sorted list from the items in *iterable*.
Kembalikan daftar baru yang diurutkan dari item di *iterable*.
Return a :class:`str` version of *object*. See :func:`str` for details.
Kembalikan sebuah versi :class:`str` dari *objek*. Lihat :func:`str` untuk detailnya.
Sums *start* and the items of an *iterable* from left to right and returns the total. The *iterable*'s items are normally numbers, and the start value is not allowed to be a string.
Jumlah *start* dan item dari *iterable* dari kiri ke kanan dan mengembalikan total. Item *iterable* biasanya berupa angka, dan nilai awal tidak boleh berupa string.
Return a proxy object that delegates method calls to a parent or sibling class of *type*. This is useful for accessing inherited methods that have been overridden in a class.
Kembalikan objek proxy yang mendelegasikan panggilan metode ke kelas orang tua atau saudara dari *type*. Ini berguna untuk mengakses metode yang diwariskan yang telah ditimpa di suatu kelas.
If the second argument is omitted, the super object returned is unbound. If the second argument is an object, ``isinstance(obj, type)`` must be true. If the second argument is a type, ``issubclass(type2, type)`` must be true (this is useful for classmethods).
Jika argumen kedua dihilangkan, objek super yang dikembalikan tidak terikat *unbound*. Jika argumen kedua adalah objek, ``isinstance(obj, type)`` harus benar. Jika argumen kedua adalah tipe, ``issubclass(type2, type)`` harus benar (ini berguna untuk metode-metode kelas).
With one argument, return the type of an *object*. The return value is a type object and generally the same object as returned by :attr:`object.__class__`.
With three arguments, return a new type object. This is essentially a dynamic form of the :keyword:`class` statement. The *name* string is the class name and becomes the :attr:`~type.__name__` attribute. The *bases* tuple contains the base classes and becomes the :attr:`~type.__bases__` attribute; if empty, :class:`object`, the ultimate base of all classes, is added. The *dict* dictionary contains attribute and method definitions for the class body; it may be copied or wrapped before becoming the :attr:`~type.__dict__` attribute. The following two statements create identical :class:`!type` objects:
Return the :attr:`~object.__dict__` attribute for a module, class, instance, or any other object with a :attr:`!__dict__` attribute.
More formally: :func:`zip` returns an iterator of tuples, where the *i*-th tuple contains the *i*-th element from each of the argument iterables.
Edge cases: With a single iterable argument, :func:`zip` returns an iterator of 1-tuples. With no arguments, it returns an empty iterator.
When the *name* variable is of the form ``package.module``, normally, the top-level package (the name up till the first dot) is returned, *not* the module named by *name*. However, when a non-empty *fromlist* argument is given, the module named by *name* is returned.
Ketika variabel *name* dalam bentuk ``package.module``, biasanya, paket tingkat atas (nama hingga titik pertama) dikembalikan, *not* modul dinamai dengan *name*. Namun, ketika argumen tidak-kosong *fromlist * diberikan, modul bernama oleh *name* dikembalikan.
Note how :func:`__import__` returns the toplevel module here because this is the object that is bound to a name by the :keyword:`import` statement.
Perhatikan caranya :func:`__import__` mengembalikan modul tingkat atas di sini karena ini adalah objek yang terikat pada nama oleh pernyataan :keyword:`import`.
Here, the ``spam.ham`` module is returned from :func:`__import__`. From this object, the names to import are retrieved and assigned to their respective names.
Di sini, modul ``spam.ham`` dikembalikan dari :func:`__import__`. Dari objek ini, nama yang akan diimpor diambil dan diisikan ke nama masing-masing.