Pelokalan
Python ID
id en
Masuk
Proyek
reference__datamodel.po Berkas proyek · python-docs-id-3.14 · Bahasa Indonesia
Modul PO Hanya lihat
Teks sumber — English
Terjemahan — Bahasa Indonesia
These are created by numeric literals and returned as results by arithmetic operators and arithmetic built-in functions. Numeric objects are immutable; once created their value never changes. Python numbers are of course strongly related to mathematical numbers, but subject to the limitations of numerical representation in computers.
These represent finite ordered sets indexed by non-negative numbers. The built-in function :func:`len` returns the number of items of a sequence. When the length of a sequence is *n*, the index set contains the numbers 0, 1, ..., *n*-1. Item *i* of sequence *a* is selected by ``a[i]``. Some sequences, including built-in sequences, interpret negative subscripts by adding the sequence length. For example, ``a[-2]`` equals ``a[n-2]``, the second to last item of sequence a with length ``n``.
The built-in function :func:`ord` converts a code point from its string form to an integer in the range ``0`` to ``0x10FFFF``; :func:`chr` converts an integer in the range ``0`` to ``0x10FFFF`` to the corresponding length ``1`` string object. :meth:`str.encode` can be used to convert a :class:`str` to :class:`bytes` using the given text encoding, and :meth:`bytes.decode` can be used to achieve the opposite.
These represent unordered, finite sets of unique, immutable objects. As such, they cannot be indexed by any subscript. However, they can be iterated over, and the built-in function :func:`len` returns the number of items in a set. Common uses for sets are fast membership testing, removing duplicates from a sequence, and computing mathematical operations such as intersection, union, difference, and symmetric difference.
These represent finite sets of objects indexed by arbitrary index sets. The subscript notation ``a[k]`` selects the item indexed by ``k`` from the mapping ``a``; this can be used in expressions and as the target of assignments or :keyword:`del` statements. The built-in function :func:`len` returns the number of items in a mapping.
CPython's current implementation only supports function attributes on user-defined functions. Function attributes on :ref:`built-in functions <builtin-functions>` may be supported in the future.
Built-in functions
A built-in function object is a wrapper around a C function. Examples of built-in functions are :func:`len` and :func:`math.sin` (:mod:`math` is a standard built-in module). The number and type of the arguments are determined by the C function. Special read-only attributes:
This is really a different disguise of a built-in function, this time containing an object passed to the C function as an implicit extra argument. An example of a built-in method is ``alist.append()``, assuming *alist* is a list object. In this case, the special read-only attribute :attr:`!__self__` is set to the object denoted by *alist*. (The attribute has the same semantics as it does with :attr:`other instance methods <method.__self__>`.)
A :term:`file object` represents an open file. Various shortcuts are available to create file objects: the :func:`open` built-in function, and also :func:`os.popen`, :func:`os.fdopen`, and the :meth:`~socket.socket.makefile` method of socket objects (and perhaps by other functions or methods provided by extension modules).
Called by the :func:`repr` built-in function to compute the "official" string representation of an object. If at all possible, this should look like a valid Python expression that could be used to recreate an object with the same value (given an appropriate environment). If this is not possible, a string of the form ``<...some useful description...>`` should be returned. The return value must be a string object. If a class defines :meth:`__repr__` but not :meth:`__str__`, then :meth:`__repr__` is also used when an "informal" string representation of instances of that class is required.
Called by :func:`str(object) <str>`, the default :meth:`__format__` implementation, and the built-in function :func:`print`, to compute the "informal" or nicely printable string representation of an object. The return value must be a :ref:`str <textseq>` object.
Called by the :func:`format` built-in function, and by extension, evaluation of :ref:`formatted string literals <f-strings>` and the :meth:`str.format` method, to produce a "formatted" string representation of an object. The *format_spec* argument is a string that contains a description of the formatting options desired. The interpretation of the *format_spec* argument is up to the type implementing :meth:`__format__`, however most classes will either delegate formatting to one of the built-in types, or use a similar formatting option syntax.
Called by built-in function :func:`hash` and for operations on members of hashed collections including :class:`set`, :class:`frozenset`, :class:`dict`, and :class:`frozendict`. The ``__hash__()`` method should return an integer. The only required property is that objects which compare equal have the same hash value; it is advised to mix together the hash values of the components of the object that also play a part in comparison of objects by packing them into a tuple and hashing the tuple. Example::
This method may still be bypassed when looking up special methods as the result of implicit invocation via language syntax or :ref:`built-in functions <builtin-functions>`. See :ref:`special-lookup`.
The following methods are used to override the default behavior of the :func:`isinstance` and :func:`issubclass` built-in functions.
Called to implement the built-in function :func:`len`. Should return the length of the object, an integer ``>=`` 0. Also, an object that doesn't define a :meth:`~object.__bool__` method and whose :meth:`!__len__` method returns zero is considered to be false in a Boolean context.
Called to implement the built-in functions :func:`complex`, :func:`int` and :func:`float`. Should return a value of the appropriate type.
If :meth:`__int__`, :meth:`__float__` and :meth:`__complex__` are not defined then corresponding built-in functions :func:`int`, :func:`float` and :func:`complex` fall back to :meth:`__index__`.
Called to implement the built-in function :func:`round` and :mod:`math` functions :func:`~math.trunc`, :func:`~math.floor` and :func:`~math.ceil`. Unless *ndigits* is passed to :meth:`!__round__` all these methods should return the value of the object truncated to an :class:`~numbers.Integral` (typically an :class:`int`).
built-in function
fungsi bawaan
repr() (built-in function)
format() (built-in function)
print() (built-in function)