Pelokalan
Python ID
id en
Masuk
Proyek
builtins__functions.po Berkas proyek · python-docs-id-3.14 · Bahasa Indonesia
Modul PO Hanya lihat
Teks sumber — English
Terjemahan — Bahasa Indonesia
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`).
If it is a *string*, you must also give the *encoding* (and optionally, *errors*) parameters; :func:`bytearray` then converts the string to bytes using :meth:`str.encode`.
Jika ini adalah *string*, Anda juga harus memberikan parameter *encoding* (dan opsional, *errors*); :func:`bytearray` kemudian mengonversi string menjadi byte menggunakan :meth:`str.encode`.
Convert a single string or number to a complex number, or create a complex number from real and imaginary parts.
Convert a *value* to a "formatted" representation, as controlled by *format_spec*. The interpretation of *format_spec* will depend on the type of the *value* argument; however, there is a standard formatting syntax that is used by most built-in types: :ref:`formatspec`.
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:
See also :func:`int` for converting a hexadecimal string to an integer using a base of 16.
Lihat juga :func:`int` untuk mengonversi string heksadesimal menjadi integer menggunakan basis 16.
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::
:class:`int` string inputs and string representations can be limited to help avoid denial of service attacks. A :exc:`ValueError` is raised when the limit is exceeded while converting a string to an :class:`int` or when converting an :class:`int` into a string would exceed the limit. See the :ref:`integer string conversion length limitation <int_max_str_digits>` documentation.
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.
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``.
All non-keyword arguments are converted to strings like :func:`str` does and written to the stream, separated by *sep* and followed by *end*. Both *sep* and *end* must be strings; they can also be ``None``, which means to use the default values. If no *objects* are given, :func:`print` will just write *end*.
Semua argumen non-kata kunci dikonversi ke string seperti :func:`str` dan ditulis ke aliran *stream*, dipisahkan oleh *sep* dan diikuti oleh *end*. Baik *sep* dan *end* harus berupa string; mereka juga bisa ``None``, yang berarti menggunakan nilai bawaan. Jika tidak ada *objects* yang diberikan, :func:`print` hanya akan menulis *end*.
The *file* argument must be an object with a ``write(string)`` method; if it is not present or ``None``, :data:`sys.stdout` will be used. Since printed arguments are converted to text strings, :func:`print` cannot be used with binary mode file objects. For these, use ``file.write(...)`` instead.
Argumen *file* harus berupa objek dengan metode ``write(string)``; jika tidak ada atau ``None``, :data:`sys.stdout` akan digunakan. Karena argumen yang dicetak dikonversi ke string teks, :func:`print` tidak dapat digunakan dengan objek file mode biner. Untuk ini, gunakan ``file.write(...)`` sebagai gantinya.
Use :func:`functools.cmp_to_key` to convert an old-style *cmp* function to a *key* function.
Gunakan :func:`functools.cmp_to_key` untuk mengubah fungsi *cmp* gaya lama menjadi fungsi *key*.