Pelokalan
Python ID
id en
Masuk
Proyek
reference__simple_stmts.po Berkas proyek · python-docs-id-3.14 · Bahasa Indonesia
Modul PO Hanya lihat
Teks sumber — English
Terjemahan — Bahasa Indonesia
An expression statement evaluates the expression list (which may be a single expression).
An assignment statement evaluates the expression list (remember that this can be a single expression or a comma-separated list, the latter yielding a tuple) and assigns the single resulting object to each of the target lists, from left to right.
Assignment is defined recursively depending on the form of the target (list). When a target is part of a mutable object (an attribute reference or subscription), the mutable object must ultimately perform the assignment and decide about its validity, and may raise an exception if the assignment is unacceptable. The rules observed by various types and the exceptions raised are given with the definition of the object types (see section :ref:`types`).
Assignment of an object to a target list, optionally enclosed in parentheses or square brackets, is recursively defined as follows.
If the target list is a single target with no trailing comma, optionally in parentheses, the object is assigned to that target.
If the target list contains one target prefixed with an asterisk, called a "starred" target: The object must be an iterable with at least as many items as there are targets in the target list, minus one. The first items of the iterable are assigned, from left to right, to the targets before the starred target. The final items of the iterable are assigned to the targets after the starred target. A list of the remaining items in the iterable is then assigned to the starred target (the list can be empty).
Else: The object must be an iterable with the same number of items as there are targets in the target list, and the items are assigned, from left to right, to the corresponding targets.
Typically, :meth:`~object.__setitem__` is defined on mutable sequence objects (such as lists) and mapping objects (such as dictionaries), and behaves as follows.
If the primary is a mutable sequence object (such as a list), the subscript must yield an integer. If it is negative, the sequence's length is added to it. The resulting value must be a nonnegative integer less than the sequence's length, and the sequence is asked to assign the assigned object to its item with that index. If the index is out of range, :exc:`IndexError` is raised (assignment to a subscripted sequence cannot add new items to a list).
If the target is a slicing: The primary expression should evaluate to a mutable sequence object (such as a list). The assigned object should be :term:`iterable`. The slicing's lower and upper bounds should be integers; if they are ``None`` (or not present), the defaults are zero and the sequence's length. If either bound is negative, the sequence's length is added to it. The resulting bounds are clipped to lie between zero and the sequence's length, inclusive. Finally, the sequence object is asked to replace the slice with the items of the assigned sequence. The length of the slice may be different from the length of the assigned sequence, thus changing the length of the target sequence, if the target sequence allows it.
An augmented assignment evaluates the target (which, unlike normal assignment statements, cannot be an unpacking) and the expression list, performs the binary operation specific to the type of assignment on the two operands, and assigns the result to the original target. The target is only evaluated once.
Deletion of a target list recursively deletes each target, from left to right.
If an expression list is present, it is evaluated, else ``None`` is substituted.
:keyword:`return` leaves the current function call with the expression list (or ``None``) as return value.
If the list of identifiers is replaced by a star (``'*'``), all public names defined in the module are bound in the local namespace for the scope where the :keyword:`import` statement occurs.
All historical features enabled by the future statement are still recognized by Python 3. The list includes ``absolute_import``, ``division``, ``generators``, ``generator_stop``, ``unicode_literals``, ``print_function``, ``nested_scopes`` and ``with_statement``. They are all redundant because they are always enabled, and only kept for backwards compatibility.
The :keyword:`global` statement causes the listed identifiers to be interpreted as globals. It would be impossible to assign to a global variable without :keyword:`!global`, although free variables may refer to globals without being declared global.
When the definition of a function or class is nested (enclosed) within the definitions of other functions, its nonlocal scopes are the local scopes of the enclosing functions. The :keyword:`nonlocal` statement causes the listed identifiers to refer to names previously bound in nonlocal scopes. It allows encapsulated code to rebind such nonlocal identifiers. If a name is bound in more than one nonlocal scope, the nearest binding is used. If a name is not bound in any nonlocal scope, or if there is no nonlocal scope, a :exc:`SyntaxError` is raised.
Type aliases may be made generic by adding a :ref:`type parameter list <type-params>` after the name. See :ref:`generic-type-aliases` for more.
list
list
in target list
in assignment target list
expression list
identifier list