Pelokalan
Python ID
id en
Sign in
Project
builtins__functions.po Project files · python-docs-id-3.14 · Bahasa Indonesia
Module PO View only
Source text — English
Translation — Bahasa Indonesia
The optional *source* parameter can be used to initialize the array in a few different ways:
Parameter opsional *source* dapat digunakan untuk menginisialisasi array dengan beberapa cara berbeda:
If it is an object conforming to the :ref:`buffer interface <bufferobjects>`, a read-only buffer of the object will be used to initialize the bytes array.
Jika itu adalah objek yang sesuai dengan :ref:`buffer interface <bufferobjects>`, buffer yang hanya baca dari objek tersebut akan digunakan untuk menginisialisasi array byte.
If it is an *iterable*, it must be an iterable of integers in the range ``0 <= x < 256``, which are used as the initial contents of the array.
Jika ini adalah *iterable*, itu harus iterable dari bilangan bulat dalam kisaran ``0 <= x < 256``, yang digunakan sebagai konten awal array.
The *filename* argument should give the file from which the code was read; pass some recognizable value if it wasn't read from a file (``'<string>'`` is commonly used).
Argumen *filename* harus memberikan berkas dari mana kode dibaca; berikan nilai yang dapat dikenali jika tidak dibaca dari berkas (``'<string>'`` biasa digunakan).
The optional arguments *flags* and *dont_inherit* control which :ref:`compiler options <ast-compiler-flags>` should be activated and which :ref:`future features <future>` should be allowed. If neither is present (or both are zero) the code is compiled with the same flags that affect the code that is calling :func:`compile`. If the *flags* argument is given and *dont_inherit* is not (or is zero) then the compiler options and the future statements specified by the *flags* argument are used in addition to those that would be used anyway. If *dont_inherit* is a non-zero integer then the *flags* argument is it -- the flags (future features and compiler options) in the surrounding code are ignored.
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.
The *source* argument is parsed and evaluated as a Python expression (technically speaking, an :ref:`expression list <exprlists>`) using the *globals* and *locals* mappings as global and local namespace. If the *globals* dictionary is present and does not contain a value for the key ``__builtins__``, a reference to the dictionary of the built-in module :mod:`builtins` is inserted under that key before *source* is parsed. Overriding ``__builtins__`` can be used to restrict or change the available names, but this is **not** a security mechanism: the executed code can still access all builtins. If the *locals* mapping is omitted it defaults to the *globals* dictionary. If both mappings are omitted, the source is executed with the *globals* and *locals* in the environment where :func:`eval` is called. Note, *eval()* will only have access to the :term:`nested scopes <nested scope>` (non-locals) in the enclosing environment if they are already referenced in the scope that is calling :func:`eval` (e.g. via a :keyword:`nonlocal` statement).
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``.
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``.
In all cases, if the optional parts are omitted, the code is executed in the current scope. If only *globals* is provided, it must be a dictionary (and not a subclass of dictionary), which will be used for both the global and the local variables. If *globals* and *locals* are given, they are used for the global and local variables, respectively. If provided, *locals* can be any mapping object. Remember that at the module level, globals and locals are the same dictionary.
If the *globals* dictionary does not contain a value for the key ``__builtins__``, a reference to the dictionary of the built-in module :mod:`builtins` is inserted under that key. Overriding ``__builtins__`` can be used to restrict or change the available names, but this is **not** a security mechanism: the executed code can still access all builtins.
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`.
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).
If *base* is not an instance of :class:`int` and the *base* object has a :meth:`base.__index__ <object.__index__>` method, that method is called to obtain an integer for the base. Previous versions used :meth:`base.__int__ <object.__int__>` instead of :meth:`base.__index__ <object.__index__>`.
Jika *base* bukan turunan dari :class:`int` dan objek *base* memiliki metode :meth:`base.__index__ <object.__index__>`, metode itu dipanggil untuk mendapatkan integer untuk basis. Versi sebelumnya menggunakan <object.__int__>` alih-alih :meth: `base.__index__ <object.__index__>`.
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.
*mode* is an optional string that specifies the mode in which the file is opened. It defaults to ``'r'`` which means open for reading in text mode. Other common values are ``'w'`` for writing (truncating the file if it already exists), ``'x'`` for exclusive creation, and ``'a'`` for appending (which on *some* Unix systems, means that *all* writes append to the end of the file regardless of the current seek position). In text mode, if *encoding* is not specified, UTF-8 is used by default; if :ref:`Python UTF-8 Mode <utf8-mode>` is disabled, :func:`locale.getencoding` is called to get the current locale encoding. (For reading and writing raw bytes use binary mode and leave *encoding* unspecified.) The available modes are:
*buffering* is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable when writing in text mode), and an integer > 1 to indicate the size in bytes of a fixed-size chunk buffer. Note that specifying a buffer size this way applies for binary buffered I/O, but ``TextIOWrapper`` (i.e., files opened with ``mode='r+'``) would have another buffering. To disable buffering in ``TextIOWrapper``, consider using the ``write_through`` flag for :func:`io.TextIOWrapper.reconfigure`. When no *buffering* argument is given, the default buffering policy works as follows:
*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.
*errors* is an optional string that specifies how encoding and decoding errors are to be handled—this cannot be used in binary mode. A variety of standard error handlers are available, though any error handling name that has been registered with :func:`codecs.register_error` is also valid. The standard names can be found in :ref:`error-handlers`.
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``).
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.
:exc:`IOError` used to be raised, it is now an alias of :exc:`OSError`.
:exc:`IOError` sebelumnya ditimbulkan, sekarang merupakan alias dari :exc:`OSError`.
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.
Return a new unique sentinel object. *name* must be a :class:`str`, and is used by default as the returned object's representation::
The optional *repr* argument can be used to specify a different representation::
Sentinels are conventionally assigned to a variable with a matching name. Sentinels defined in this way can be used in :term:`type hints <type hint>`::
Slice objects are also generated when :ref:`slicing syntax <slicings>` is used. For example: ``a[start:stop:step]`` or ``a[start:stop, i]``.
These read-only attributes are set to the argument values (or their default). They have no other explicit functionality; however, they are used by NumPy and other third-party packages.
*key* specifies a function of one argument that is used to extract a comparison key from each element in *iterable* (for example, ``key=str.lower``). The default value is ``None`` (compare the elements directly).
*key* menentukan sebuah fungsi dari satu argumen yang digunakan untuk mengekstrak kunci perbandingan dari setiap elemen di *iterable* (misalnya, ``key=str.lower``). Nilai bawaannya adalah ``None`` (bandingkan elemen secara langsung).
A static method can be called either on the class (such as ``C.f()``) or on an instance (such as ``C().f()``). Moreover, the static method :term:`descriptor` is also callable, so it can be used in the class definition (such as ``f()``).
The :attr:`~type.__mro__` attribute of the class corresponding to *object_or_type* lists the method resolution search order used by both :func:`getattr` and :func:`super`. The attribute is dynamic and can change whenever the inheritance hierarchy is updated.
There are two typical use cases for *super*. In a class hierarchy with single inheritance, *super* can be used to refer to parent classes without naming them explicitly, thus making the code more maintainable. This use closely parallels the use of *super* in other programming languages.
Ada dua kasus penggunaan khas untuk *super*. Dalam hierarki kelas dengan pewarisan tunggal *single inheritance*, *super* dapat digunakan untuk merujuk ke kelas induk tanpa menyebutkannya secara eksplisit, sehingga membuat kode lebih mudah dikelola. Penggunaan ini sangat mirip dengan penggunaan *super* dalam bahasa pemrograman lain.
:func:`zip` is often used in cases where the iterables are assumed to be of equal length. In such cases, it's recommended to use the ``strict=True`` option. Its output is the same as regular :func:`zip`::
:func:`zip` in conjunction with the ``*`` operator can be used to unzip a list::
:func:`zip` bersama dengan operator ``*`` dapat digunakan untuk *unzip* sebuah list atau daftar::
When the command line options :option:`-E` or :option:`-I` are being used, the environment variable :envvar:`PYTHONCASEOK` is now ignored.