Teks sumber — English
Terjemahan — Bahasa Indonesia
The Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order.
Interpreter Python memiliki sejumlah fungsi dan tipe bawaan di dalamnya yang selalu tersedia. Mereka terdaftar di sini dalam urutan abjad.
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.
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:
Convert a single string or number to a complex number, or create a complex number from real and imaginary parts.
If the argument is a string, it must contain either a real part (in the same format as for :func:`float`) or an imaginary part (in the same format but with a ``'j'`` or ``'J'`` suffix), or both real and imaginary parts (the sign of the imaginary part is mandatory in this case). The string can optionally be surrounded by whitespaces and the round parentheses ``'('`` and ``')'``, which are ignored. The string must not contain whitespace between ``'+'``, ``'-'``, the ``'j'`` or ``'J'`` suffix, and the decimal number. For example, ``complex('1+2j')`` is fine, but ``complex('1 + 2j')`` raises :exc:`ValueError`. More precisely, the input must conform to the :token:`~float:complexvalue` production rule in the following grammar, after parentheses and leading and trailing whitespace characters are removed:
If the argument is a number, the constructor serves as a numeric conversion like :class:`int` and :class:`float`. For a general Python object ``x``, ``complex(x)`` delegates to ``x.__complex__()``. If :meth:`~object.__complex__` is not defined then it falls back to :meth:`~object.__float__`. If :meth:`!__float__` is not defined then it falls back to :meth:`~object.__index__`.
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.
See also :meth:`complex.from_number` which only accepts a single numeric argument.
Passing a complex number as the *real* or *imag* argument is now deprecated; it should only be passed as a single positional argument.
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 a floating-point number constructed from a number or a string.
If the argument is a string, it should contain a decimal number, optionally preceded by a sign, and optionally embedded in whitespace. The optional sign may be ``'+'`` or ``'-'``; a ``'+'`` sign has no effect on the value produced. The argument may also be a string representing a NaN (not-a-number), or positive or negative infinity. More precisely, the input must conform to the :token:`~float:floatvalue` production rule in the following grammar, after leading and trailing whitespace characters are removed:
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.
See also :meth:`float.from_number` which only accepts a numeric argument.
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:
If you want to convert an integer number to an uppercase or lower hexadecimal string with prefix or not, you can use either of the following ways:
Jika Anda ingin mengonversi bilangan bulat menjadi string heksadesimal huruf besar atau huruf kecil dengan awalan atau tidak, Anda dapat menggunakan salah satu dari cara berikut:
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.
If the argument is not a number or if *base* is given, then it must be a string, :class:`bytes`, or :class:`bytearray` instance representing an integer in radix *base*. Optionally, the string can be preceded by ``+`` or ``-`` (with no space in between), have leading zeros, be surrounded by whitespace, and have single underscores interspersed between digits.
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*).
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:
If you want to convert an integer number to an octal string either with the prefix "0o" or not, you can use either of the following ways.
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*.
For a general Python object ``number``, ``round`` delegates to ``number.__round__``.
Untuk sebuah objek Python ``number`` secara umum, ``round`` mendelegasikan ke ``number.__round__``.
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.