diff --git a/faq/programming.po b/faq/programming.po index 0efa296645..eaa2fc009d 100644 --- a/faq/programming.po +++ b/faq/programming.po @@ -911,7 +911,7 @@ msgstr "" "我們可以看到,在這種情況下 ``x`` 和 ``y`` 不再相等。這是因為整數是 " ":term:`immutable`,當我們執行 ``x = x + 1`` 時,我們並沒有透過增加 int " "``5`` 的值來改變它;相反地,我們建立了一個新物件(int ``6``)並將其賦值" -"給 ``x``(也就是說,更改 ``x`` 所參照的物件)。在這個賦值之後,我們有兩" +"給 ``x``\\ (也就是說,更改 ``x`` 所參照的物件)。在這個賦值之後,我們有兩" "個物件(整數 ``6`` 和 ``5``)和兩個參照它們的變數(``x`` 現在參照 " "``6``,但 ``y`` 仍然參照 ``5``)。" diff --git a/reference/simple_stmts.po b/reference/simple_stmts.po index c3d85c07db..b4d581e6a7 100644 --- a/reference/simple_stmts.po +++ b/reference/simple_stmts.po @@ -2,12 +2,14 @@ # This file is distributed under the same license as the Python package. # # Translators: +# Adrian Liaw , 2018 +# Matt Wang , 2026 msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-02-06 00:18+0000\n" -"PO-Revision-Date: 2018-05-23 16:17+0000\n" +"POT-Creation-Date: 2026-02-27 02:51+0800\n" +"PO-Revision-Date: 2026-02-27 16:17+0800\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -27,10 +29,12 @@ msgid "" "statements may occur on a single line separated by semicolons. The syntax " "for simple statements is:" msgstr "" +"一個簡單陳述式會被包含在一個單獨的邏輯列中。多個簡單陳述式用分號分隔就可以出" +"現在同一列中。簡單陳述式的語法如下:" #: ../../reference/simple_stmts.rst:37 msgid "Expression statements" -msgstr "" +msgstr "運算式陳述式" #: ../../reference/simple_stmts.rst:44 msgid "" @@ -40,12 +44,16 @@ msgid "" "uses of expression statements are allowed and occasionally useful. The " "syntax for an expression statement is:" msgstr "" +"運算式陳述式(主要在互動模式下)用於計算並寫入一個值,或者(通常)用於呼叫一" +"個程序 (procedure)(一個不回傳有意義結果的函式;在 Python 中,程序會回傳 " +"``None`` 值)。運算式陳述式的其他用途也是被允許的,並且偶爾會很有用。運算式陳" +"述式的語法如下:" #: ../../reference/simple_stmts.rst:53 msgid "" "An expression statement evaluates the expression list (which may be a single " "expression)." -msgstr "" +msgstr "運算式陳述式會對運算式串列(可能是單個運算式)進行求值 (evaluate)。" #: ../../reference/simple_stmts.rst:65 msgid "" @@ -54,22 +62,27 @@ msgid "" "written to standard output on a line by itself (except if the result is " "``None``, so that procedure calls do not cause any output.)" msgstr "" +"在互動模式下,如果值不是 ``None``,就會以內建的 :func:`repr` 函式轉換成字串," +"並將結果字串單獨寫入標準輸出的一列中(除非結果是 ``None``,則程序呼叫就不會產" +"生任何輸出)。" #: ../../reference/simple_stmts.rst:73 msgid "Assignment statements" -msgstr "" +msgstr "賦值陳述式" #: ../../reference/simple_stmts.rst:83 msgid "" "Assignment statements are used to (re)bind names to values and to modify " "attributes or items of mutable objects:" -msgstr "" +msgstr "賦值陳述式用於將名稱(重新)繫結到值,以及修改可變物件的屬性或項目:" #: ../../reference/simple_stmts.rst:96 msgid "" "(See section :ref:`primaries` for the syntax definitions for *attributeref* " "and *subscription*.)" msgstr "" +"(關於 *attributeref* 和 *subscription* 的語法定義,請參閱 :ref:`primaries` " +"章節。)" #: ../../reference/simple_stmts.rst:99 msgid "" @@ -78,6 +91,8 @@ msgid "" "tuple) and assigns the single resulting object to each of the target lists, " "from left to right." msgstr "" +"賦值陳述式會對運算式串列進行求值(請記住,這可以是單個運算式或以逗號分隔的串" +"列,後者會產生一個元組),並將單個結果物件從左到右賦值給每個目標串列。" #: ../../reference/simple_stmts.rst:108 msgid "" @@ -88,22 +103,30 @@ msgid "" "unacceptable. The rules observed by various types and the exceptions raised " "are given with the definition of the object types (see section :ref:`types`)." msgstr "" +"賦值是根據目標(串列)的形式遞迴定義的。當目標是可變物件的一部分(屬性參照或" +"下標)時,該可變物件最終必須執行賦值並決定其有效性,如果賦值不被接受則可能會" +"引發例外。各種型別遵循的規則以及引發的例外在物件型別的定義中給定(請參" +"閱\\ :ref:`types`\\ 章節)。" #: ../../reference/simple_stmts.rst:121 msgid "" "Assignment of an object to a target list, optionally enclosed in parentheses " "or square brackets, is recursively defined as follows." msgstr "" +"將物件賦值給目標串列(可選擇性地用圓括號或方括號括起來)是以下列方式遞迴定義" +"的。" #: ../../reference/simple_stmts.rst:124 msgid "" "If the target list is a single target with no trailing comma, optionally in " "parentheses, the object is assigned to that target." msgstr "" +"如果目標串列是單個目標且沒有尾隨逗號(可選擇性地用圓括號括起來),則物件會被" +"賦值給該目標。" #: ../../reference/simple_stmts.rst:127 msgid "Else:" -msgstr "" +msgstr "否則:" #: ../../reference/simple_stmts.rst:129 msgid "" @@ -115,6 +138,11 @@ msgid "" "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)." msgstr "" +"如果目標串列包含一個以星號為前綴的目標,稱為 \"starred\" 目標:該物件必須是一個" +"可疊代物件,其項目數量至少與目標串列中的目標數量減一一樣多。可疊代物件的前幾" +"個項目從左到右賦值給 starred 目標之前的目標。可疊代物件的最後幾個項目賦值給 " +"starred 目標之後的目標。然後可疊代物件中剩餘項目的串列會被賦值給 starred 目" +"標(該串列可以為空)。" #: ../../reference/simple_stmts.rst:137 msgid "" @@ -122,15 +150,17 @@ msgid "" "are targets in the target list, and the items are assigned, from left to " "right, to the corresponding targets." msgstr "" +"否則:該物件必須是一個可疊代物件,其項目數量與目標串列中的目標數量相同,並且" +"這些項目從左到右賦值給對應的目標。" #: ../../reference/simple_stmts.rst:141 msgid "" "Assignment of an object to a single target is recursively defined as follows." -msgstr "" +msgstr "將物件賦值給單個目標是以下列方式遞迴定義的。" #: ../../reference/simple_stmts.rst:143 msgid "If the target is an identifier (name):" -msgstr "" +msgstr "如果目標是一個識別字(名稱):" #: ../../reference/simple_stmts.rst:145 msgid "" @@ -138,12 +168,16 @@ msgid "" "statement in the current code block: the name is bound to the object in the " "current local namespace." msgstr "" +"如果該名稱沒有出現在當前程式碼區塊的 :keyword:`global` " +"或 :keyword:`nonlocal` 陳述式中:該名稱會被繫結到當前區域命名空間中的物件。" #: ../../reference/simple_stmts.rst:149 msgid "" "Otherwise: the name is bound to the object in the global namespace or the " "outer namespace determined by :keyword:`nonlocal`, respectively." msgstr "" +"否則:該名稱分別被繫結到全域命名空間或由 :keyword:`nonlocal` 決定的外層命名空" +"間中的物件。" #: ../../reference/simple_stmts.rst:154 msgid "" @@ -151,6 +185,8 @@ msgid "" "count for the object previously bound to the name to reach zero, causing the " "object to be deallocated and its destructor (if it has one) to be called." msgstr "" +"如果名稱已經被繫結,則會重新繫結。這可能導致先前繫結到該名稱的物件的參照計數" +"變為零,從而導致該物件被釋放並呼叫其解構函式(如果有的話)。" #: ../../reference/simple_stmts.rst:160 msgid "" @@ -161,6 +197,10 @@ msgid "" "if it cannot perform the assignment, it raises an exception (usually but not " "necessarily :exc:`AttributeError`)." msgstr "" +"如果目標是屬性參照:參照中的主要運算式會被求值。它應該產生一個具有可賦值屬性" +"的物件;如果不是這種情況,則會引發 :exc:`TypeError`。然後要求該物件將被賦值的" +"物件賦值給指定的屬性;如果它無法執行賦值,則會引發例外(通常" +"是 :exc:`AttributeError` 但並非一定)。" #: ../../reference/simple_stmts.rst:169 msgid "" @@ -173,6 +213,11 @@ msgid "" "the right-hand side expression refers to a class attribute, the left-hand " "side creates a new instance attribute as the target of the assignment::" msgstr "" +"注意:如果物件是類別實例,且屬性參照出現在賦值運算子的兩側,右側運算式 " +"``a.x`` 可以存取實例屬性或(如果不存在實例屬性)類別屬性。左側目標 ``a.x`` 總" +"是被設定為實例屬性,如有必要會建立它。因此,``a.x`` 的兩次出現不一定指向同一" +"個屬性:如果右側運算式參照的是類別屬性,左側會建立一個新的實例屬性作為賦值的" +"目標: ::" #: ../../reference/simple_stmts.rst:178 msgid "" @@ -181,12 +226,18 @@ msgid "" "inst = Cls()\n" "inst.x = inst.x + 1 # writes inst.x as 4 leaving Cls.x as 3" msgstr "" +"class Cls:\n" +" x = 3 # 類別變數\n" +"inst = Cls()\n" +"inst.x = inst.x + 1 # 將 inst.x 寫為 4,Cls.x 保持為 3" #: ../../reference/simple_stmts.rst:183 msgid "" "This description does not necessarily apply to descriptor attributes, such " "as properties created with :func:`property`." msgstr "" +"此描述不一定適用於描述器屬性,例如使用 :func:`property` 建立的特性 " +"(property)。" #: ../../reference/simple_stmts.rst:190 msgid "" @@ -195,6 +246,9 @@ msgid "" "meth:`~object.__setitem__` method is called with two arguments: the " "subscript and the assigned object." msgstr "" +"如果目標是下標:參照中的主要運算式會被求值。接著,下標運算式會被求值。然後" +"會以兩個引數(下標和被賦值的物件)呼叫主要物件的 :meth:`~object.__setitem__` " +"方法。" #: ../../reference/simple_stmts.rst:196 msgid "" @@ -202,6 +256,8 @@ msgid "" "objects (such as lists) and mapping objects (such as dictionaries), and " "behaves as follows." msgstr "" +"通常 :meth:`~object.__setitem__` 被定義在可變序列物件(如串列)和對映物件(如字" +"典)上,其行為如下。" #: ../../reference/simple_stmts.rst:204 msgid "" @@ -213,6 +269,10 @@ msgid "" "`IndexError` is raised (assignment to a subscripted sequence cannot add new " "items to a list)." msgstr "" +"如果主要物件是可變序列物件(如串列),下標必須產生一個整數。如果它是負數,會" +"加上序列的長度。結果值必須是一個非負整數且小於序列的長度,然後要求該序列將" +"被賦值的物件賦值給具有該索引的項目。如果索引超出範圍,則會引" +"發 :exc:`IndexError`\\ (對下標序列的賦值無法向串列新增項目)。" #: ../../reference/simple_stmts.rst:215 msgid "" @@ -223,6 +283,9 @@ msgid "" "the same key value, or insert a new key/value pair (if no key with the same " "value existed)." msgstr "" +"如果主要物件是對映物件(如字典),下標的型別必須與對映的鍵型別相容,然後要求該對" +"映建立一個將下標對映到被賦值物件的鍵/值對。這可以替換具有相同鍵值的現有鍵/" +"值對,或插入新的鍵/值對(如果不存在相同值的鍵)。" #: ../../reference/simple_stmts.rst:223 msgid "" @@ -237,6 +300,12 @@ msgid "" "be different from the length of the assigned sequence, thus changing the " "length of the target sequence, if the target sequence allows it." msgstr "" +"如果目標是切片:主要運算式應該求值為一個可變序列物件(如串列)。被賦值的物件" +"應該是\\ :term:`可疊代的 `。切片的下界和上界應該是整數;如果它們是 " +"``None``\\ (或不存在),預設值為零和序列的長度。如果任一邊界為負數,則會加上" +"序列的長度。結果邊界會被裁剪到零和序列長度之間(包含邊界)。最後,要求該序列" +"物件用被賦值序列的項目替換切片。切片的長度可能與被賦值序列的長度不同,因此會" +"改變目標序列的長度(如果目標序列允許的話)。" #: ../../reference/simple_stmts.rst:235 msgid "" @@ -246,6 +315,9 @@ msgid "" "variables occur left-to-right, sometimes resulting in confusion. For " "instance, the following program prints ``[0, 2]``::" msgstr "" +"雖然賦值的定義意味著左側和右側之間的重疊是「同時的」(例如 ``a, b = b, a`` 會" +"交換兩個變數),但被賦值變數集合\\ *內部*\\ 的重疊是從左到右發生的,有時會導" +"致混淆。例如,以下程式會印出 ``[0, 2]``: ::" #: ../../reference/simple_stmts.rst:241 msgid "" @@ -261,11 +333,11 @@ msgstr "" #: ../../reference/simple_stmts.rst:249 msgid ":pep:`3132` - Extended Iterable Unpacking" -msgstr "" +msgstr ":pep:`3132` - 擴充可疊代物件拆解" #: ../../reference/simple_stmts.rst:250 msgid "The specification for the ``*target`` feature." -msgstr "" +msgstr "``*target`` 功能的規格說明。" #: ../../reference/simple_stmts.rst:256 msgid "Augmented assignment statements" @@ -275,13 +347,13 @@ msgstr "擴增賦值陳述式" msgid "" "Augmented assignment is the combination, in a single statement, of a binary " "operation and an assignment statement:" -msgstr "" +msgstr "擴增賦值是將二元運算與賦值陳述式結合在單一陳述式中:" #: ../../reference/simple_stmts.rst:283 msgid "" "(See section :ref:`primaries` for the syntax definitions of the last three " "symbols.)" -msgstr "" +msgstr "(關於最後三個符號的語法定義,請參閱 :ref:`primaries` 章節。)" #: ../../reference/simple_stmts.rst:286 msgid "" @@ -291,6 +363,9 @@ msgid "" "operands, and assigns the result to the original target. The target is only " "evaluated once." msgstr "" +"擴增賦值會對目標(與一般賦值陳述式不同,它不能是拆解運算)和運算式串列進行求" +"值,對這兩個運算元執行該賦值型別特定的二元運算,並將結果賦值給原始目標。目標" +"只會被求值一次。" #: ../../reference/simple_stmts.rst:291 msgid "" @@ -300,6 +375,10 @@ msgid "" "operation is performed *in-place*, meaning that rather than creating a new " "object and assigning that to the target, the old object is modified instead." msgstr "" +"像 ``x += 1`` 這樣的擴增賦值陳述式可以改寫為 ``x = x + 1`` 來達到類似但不完全" +"相同的效果。在擴增版本中,``x`` 只會被求值一次。此外,在可能的情況下,實際的" +"運算會\\ *原地 (in-place)*\\ 執行,意即不是建立一個新物件並將其賦值給目標,而" +"是直接修改舊物件。" #: ../../reference/simple_stmts.rst:297 msgid "" @@ -308,6 +387,9 @@ msgid "" "first looks-up ``a[i]``, then it evaluates ``f(x)`` and performs the " "addition, and lastly, it writes the result back to ``a[i]``." msgstr "" +"與一般賦值不同,擴增賦值會在求值右側\\ *之前*\\ 先求值左側。例如,``a[i] += " +"f(x)`` 會先查找 ``a[i]``,然後求值 ``f(x)`` 並執行加法,最後將結果寫回 " +"``a[i]``。" #: ../../reference/simple_stmts.rst:302 msgid "" @@ -317,6 +399,9 @@ msgid "" "possible *in-place* behavior, the binary operation performed by augmented " "assignment is the same as the normal binary operations." msgstr "" +"除了在單一陳述式中賦值給元組和多個目標的情況外,擴增賦值陳述式執行的賦值與一" +"般賦值的處理方式相同。同樣地,除了可能的\\ *原地*\\ 行為外,擴增賦值執行的二" +"元運算與一般二元運算相同。" #: ../../reference/simple_stmts.rst:308 msgid "" @@ -324,6 +409,8 @@ msgid "" "class and instance attributes ` applies as for regular " "assignments." msgstr "" +"對於屬性參照的目標,與一般賦值相同的\\ :ref:`關於類別和實例屬性的注意事項 " +"`\\ 也適用。" #: ../../reference/simple_stmts.rst:315 msgid "Annotated assignment statements" @@ -342,7 +429,7 @@ msgstr "" msgid "" "The difference from normal :ref:`assignment` is that only a single target is " "allowed." -msgstr "" +msgstr "與一般\\ :ref:`賦值 `\\ 的區別在於只允許單個目標。" #: ../../reference/simple_stmts.rst:331 msgid "" @@ -353,18 +440,27 @@ msgid "" "be evaluated using the :attr:`~object.__annotations__` attribute of a class " "or module, or using the facilities in the :mod:`annotationlib` module." msgstr "" +"如果賦值目標由一個未被圓括號括起來的單一名稱組成,則被視為「簡單的」。對於簡" +"單的賦值目標,如果在類別或模組作用域中,註釋會被收集在一個惰性求值的\\ :ref:`" +"註釋作用域 `\\ 中。註釋可以使用類別或模組" +"的 :attr:`~object.__annotations__` 屬性來求值,或者使用 :mod:`annotationlib` " +"模組中的工具。" #: ../../reference/simple_stmts.rst:340 msgid "" "If the assignment target is not simple (an attribute, subscript node, or " "parenthesized name), the annotation is never evaluated." msgstr "" +"如果賦值目標不是簡單的(屬性、下標節點或被圓括號括起來的名稱),則註釋永遠不" +"會被求值。" #: ../../reference/simple_stmts.rst:343 msgid "" "If a name is annotated in a function scope, then this name is local for that " "scope. Annotations are never evaluated and stored in function scopes." msgstr "" +"如果一個名稱在函式作用域中被註釋,則該名稱對該作用域而言是區域的。註釋永遠不" +"會在函式作用域中被求值和儲存。" #: ../../reference/simple_stmts.rst:346 msgid "" @@ -374,10 +470,13 @@ msgid "" "the target except for the last :meth:`~object.__setitem__` or :meth:`~object." "__setattr__` call." msgstr "" +"如果右側存在,註釋賦值會執行實際的賦值,就像沒有註釋一樣。如果運算式目標的右" +"側不存在,則直譯器會對目標進行求值,但不包括最後" +"的 :meth:`~object.__setitem__` 或 :meth:`~object.__setattr__` 呼叫。" #: ../../reference/simple_stmts.rst:354 msgid ":pep:`526` - Syntax for Variable Annotations" -msgstr "" +msgstr ":pep:`526` - 變數註釋的語法" #: ../../reference/simple_stmts.rst:355 msgid "" @@ -385,6 +484,8 @@ msgid "" "(including class variables and instance variables), instead of expressing " "them through comments." msgstr "" +"此提案新增了用於註釋變數型別(包括類別變數和實例變數)的語法,取代透過註解來" +"表達的方式。" #: ../../reference/simple_stmts.rst:359 msgid ":pep:`484` - Type hints" @@ -396,6 +497,8 @@ msgid "" "syntax for type annotations that can be used in static analysis tools and " "IDEs." msgstr "" +"新增了 :mod:`typing` 模組的提案,提供了可用於靜態分析工具和 IDE 的標準型別註" +"釋語法。" #: ../../reference/simple_stmts.rst:364 msgid "" @@ -403,6 +506,8 @@ msgid "" "as regular assignments. Previously, some expressions (like un-parenthesized " "tuple expressions) caused a syntax error." msgstr "" +"現在註釋賦值允許右側與一般賦值相同的運算式。以前,某些運算式(如未加圓括號的" +"元組運算式)會導致語法錯誤。" #: ../../reference/simple_stmts.rst:369 msgid "" @@ -410,6 +515,8 @@ msgid "" "`. If the assignment target is not simple, annotations " "are never evaluated." msgstr "" +"註釋現在會在獨立的\\ :ref:`註釋作用域 `\\ 中惰性求值。如果" +"賦值目標不是簡單的,則註釋永遠不會被求值。" #: ../../reference/simple_stmts.rst:377 msgid "The :keyword:`!assert` statement" @@ -419,11 +526,11 @@ msgstr ":keyword:`!assert` 陳述式" msgid "" "Assert statements are a convenient way to insert debugging assertions into a " "program:" -msgstr "" +msgstr "Assert 陳述式是將除錯斷言插入程式中的便捷方式:" #: ../../reference/simple_stmts.rst:390 msgid "The simple form, ``assert expression``, is equivalent to ::" -msgstr "" +msgstr "簡單形式 ``assert expression`` 等價於: ::" #: ../../reference/simple_stmts.rst:392 msgid "" @@ -436,7 +543,7 @@ msgstr "" #: ../../reference/simple_stmts.rst:395 msgid "" "The extended form, ``assert expression1, expression2``, is equivalent to ::" -msgstr "" +msgstr "擴展形式 ``assert expression1, expression2`` 等價於: ::" #: ../../reference/simple_stmts.rst:397 msgid "" @@ -458,12 +565,19 @@ msgid "" "that failed in the error message; it will be displayed as part of the stack " "trace." msgstr "" +"這些等價關係假設 :const:`__debug__` 和 :exc:`AssertionError` 參照的是具有這些" +"名稱的內建變數。在目前的實作中,內建變數 ``__debug__`` 在正常情況下為 " +"``True``,在請求最佳化時(命令列選項 :option:`-O`)為 ``False``。當在編譯時請" +"求最佳化時,目前的程式碼產生器不會為 :keyword:`assert` 陳述式產生任何程式碼。" +"請注意,沒有必要在錯誤訊息中包含失敗運算式的原始碼;它會作為堆疊追蹤的一部分" +"顯示。" #: ../../reference/simple_stmts.rst:413 msgid "" "Assignments to :const:`__debug__` are illegal. The value for the built-in " "variable is determined when the interpreter starts." msgstr "" +"對 :const:`__debug__` 進行賦值是非法的。內建變數的值在直譯器啟動時決定。" #: ../../reference/simple_stmts.rst:420 msgid "The :keyword:`!pass` statement" @@ -475,6 +589,8 @@ msgid "" "happens. It is useful as a placeholder when a statement is required " "syntactically, but no code needs to be executed, for example::" msgstr "" +":keyword:`pass` 是一個空操作——當它被執行時,什麼事都不會發生。當語法上需要一" +"個陳述式但不需要執行任何程式碼時,它可以作為佔位符使用,例如: ::" #: ../../reference/simple_stmts.rst:434 msgid "" @@ -495,12 +611,14 @@ msgid "" "Deletion is recursively defined very similar to the way assignment is " "defined. Rather than spelling it out in full details, here are some hints." msgstr "" +"刪除的遞迴定義與賦值的定義方式非常相似。這裡提供一些提示,而不是詳細說明全部" +"細節。" #: ../../reference/simple_stmts.rst:455 msgid "" "Deletion of a target list recursively deletes each target, from left to " "right." -msgstr "" +msgstr "刪除目標串列會從左到右遞迴刪除每個目標。" #: ../../reference/simple_stmts.rst:461 msgid "" @@ -509,6 +627,9 @@ msgid "" "statement in the same code block. Trying to delete an unbound name raises " "a :exc:`NameError` exception." msgstr "" +"刪除名稱會從區域或全域命名空間中移除該名稱的繫結,取決於該名稱是否出現在同一" +"程式碼區塊的 :keyword:`global` 陳述式中。嘗試刪除未繫結的名稱會引" +"發 :exc:`NameError` 例外。" #: ../../reference/simple_stmts.rst:468 msgid "" @@ -517,12 +638,16 @@ msgid "" "assignment of an empty slice of the right type (but even this is determined " "by the sliced object)." msgstr "" +"屬性參照和下標的刪除會傳遞給涉及的主要物件;切片的刪除通常等價於賦值一個正確" +"型別的空切片(但這一點也是由被切片的物件決定的)。" #: ../../reference/simple_stmts.rst:473 msgid "" "Previously it was illegal to delete a name from the local namespace if it " "occurs as a free variable in a nested block." msgstr "" +"以前,如果一個名稱作為自由變數出現在巢狀區塊中,則從區域命名空間刪除該名稱是" +"非法的。" #: ../../reference/simple_stmts.rst:481 msgid "The :keyword:`!return` statement" @@ -533,18 +658,22 @@ msgid "" ":keyword:`return` may only occur syntactically nested in a function " "definition, not within a nested class definition." msgstr "" +":keyword:`return` 只能在語法上出現在函式定義的巢狀結構中,不能出現在巢狀類別" +"定義中。" #: ../../reference/simple_stmts.rst:494 msgid "" "If an expression list is present, it is evaluated, else ``None`` is " "substituted." -msgstr "" +msgstr "如果運算式串列存在,則會對其求值,否則會以 ``None`` 替代。" #: ../../reference/simple_stmts.rst:496 msgid "" ":keyword:`return` leaves the current function call with the expression list " "(or ``None``) as return value." msgstr "" +":keyword:`return` 會離開當前的函式呼叫,並以運算式串列(或 ``None``)作為回傳" +"值。" #: ../../reference/simple_stmts.rst:501 msgid "" @@ -552,6 +681,8 @@ msgid "" "a :keyword:`finally` clause, that :keyword:`!finally` clause is executed " "before really leaving the function." msgstr "" +"當 :keyword:`return` 將控制權從帶有 :keyword:`finally` 子句的 :keyword:`try` " +"陳述式中傳出時,該 :keyword:`!finally` 子句會在真正離開函式之前被執行。" #: ../../reference/simple_stmts.rst:505 msgid "" @@ -560,6 +691,9 @@ msgid "" "returned value (if any) is used as an argument to construct :exc:" "`StopIteration` and becomes the :attr:`StopIteration.value` attribute." msgstr "" +"在產生器函式中,:keyword:`return` 陳述式表示產生器已完成,並會導致引" +"發 :exc:`StopIteration`。回傳值(如果有的話)會被用作建" +"構 :exc:`StopIteration` 的引數,並成為 :attr:`StopIteration.value` 屬性。" #: ../../reference/simple_stmts.rst:510 msgid "" @@ -568,6 +702,9 @@ msgid "" "`StopAsyncIteration` to be raised. A non-empty :keyword:`!return` statement " "is a syntax error in an asynchronous generator function." msgstr "" +"在非同步產生器函式中,空的 :keyword:`return` 陳述式表示非同步產生器已完成,並" +"會導致引發 :exc:`StopAsyncIteration`。在非同步產生器函式中,非空" +"的 :keyword:`!return` 陳述式是語法錯誤。" #: ../../reference/simple_stmts.rst:518 msgid "The :keyword:`!yield` statement" @@ -580,6 +717,9 @@ msgid "" "parentheses that would otherwise be required in the equivalent yield " "expression statement. For example, the yield statements ::" msgstr "" +":keyword:`yield` 陳述式在語義上等價於\\ :ref:`yield 運算式 `。" +"``yield`` 陳述式可用於省略在等價的 yield 運算式陳述式中原本需要的圓括號。例" +"如,以下 yield 陳述式: ::" #: ../../reference/simple_stmts.rst:535 msgid "" @@ -591,7 +731,7 @@ msgstr "" #: ../../reference/simple_stmts.rst:538 msgid "are equivalent to the yield expression statements ::" -msgstr "" +msgstr "等價於以下 yield 運算式陳述式: ::" #: ../../reference/simple_stmts.rst:540 msgid "" @@ -609,12 +749,16 @@ msgid "" "cause that definition to create a generator function instead of a normal " "function." msgstr "" +"Yield 運算式和陳述式只在定義\\ :term:`產生器 `\\ 函式時使用,且只" +"在產生器函式的主體中使用。在函式定義中使用 :keyword:`yield` 就足以使該定義建" +"立一個產生器函式而非一般函式。" #: ../../reference/simple_stmts.rst:548 msgid "" "For full details of :keyword:`yield` semantics, refer to the :ref:" "`yieldexpr` section." msgstr "" +"關於 :keyword:`yield` 語義的完整詳情,請參閱\\ :ref:`yieldexpr`\\ 章節。" #: ../../reference/simple_stmts.rst:554 msgid "The :keyword:`!raise` statement" @@ -627,6 +771,9 @@ msgid "" "If there isn't currently an active exception, a :exc:`RuntimeError` " "exception is raised indicating that this is an error." msgstr "" +"如果沒有運算式,:keyword:`raise` 會重新引發當前正在處理的例外,這也稱為\\ *活" +"動例外*。如果當前沒有活動例外,則會引發 :exc:`RuntimeError` 例外,表示這是一" +"個錯誤。" #: ../../reference/simple_stmts.rst:570 msgid "" @@ -635,12 +782,17 @@ msgid "" "`BaseException`. If it is a class, the exception instance will be obtained " "when needed by instantiating the class with no arguments." msgstr "" +"否則,:keyword:`raise` 會將第一個運算式求值為例外物件。它必須" +"是 :class:`BaseException` 的子類別或實例。如果它是一個類別,則在需要時會透過" +"不帶引數地實例化該類別來獲得例外實例。" #: ../../reference/simple_stmts.rst:575 msgid "" "The :dfn:`type` of the exception is the exception instance's class, the :dfn:" "`value` is the instance itself." msgstr "" +"例外的\\ :dfn:`型別 (type)`\\ 是例外實例的類別,:dfn:`值 (value)`\\ 是實例本" +"身。" #: ../../reference/simple_stmts.rst:580 msgid "" @@ -651,6 +803,10 @@ msgid "" "returns the same exception instance, with its traceback set to its " "argument), like so::" msgstr "" +"通常在引發例外時會自動建立一個追蹤物件,並將其作" +"為 :attr:`~BaseException.__traceback__` 屬性附加到例外上。你可以使" +"用 :meth:`~BaseException.with_traceback` 例外方法(它會回傳同一個例外實例,並" +"將其追蹤設定為其引數)在一個步驟中建立例外並設定你自己的追蹤,如下所示: ::" #: ../../reference/simple_stmts.rst:586 msgid "raise Exception(\"foo occurred\").with_traceback(tracebackobj)" @@ -667,6 +823,12 @@ msgid "" "raised exception as the :attr:`!__cause__` attribute. If the raised " "exception is not handled, both exceptions will be printed:" msgstr "" +"``from`` 子句用於例外鏈結:如果給定,第二個\\ *運算式*\\ 必須是另一個例外類別" +"或實例。如果第二個運算式是例外實例,它將作" +"為 :attr:`~BaseException.__cause__` 屬性(可寫入)附加到被引發的例外上。如果" +"運算式是例外類別,則會實例化該類別,並將產生的例外實例作為 :attr:`!" +"__cause__` 屬性附加到被引發的例外上。如果被引發的例外未被處理,則兩個例外都會" +"被印出:" #: ../../reference/simple_stmts.rst:601 msgid "" @@ -714,6 +876,10 @@ msgid "" "statement, is used. The previous exception is then attached as the new " "exception's :attr:`~BaseException.__context__` attribute:" msgstr "" +"如果在已經處理一個例外時引發了新的例外,類似的機制會隱式地運作。使" +"用 :keyword:`except` 或 :keyword:`finally` 子句,或 :keyword:`with` 陳述式" +"時,例外可能正在被處理。然後先前的例外會作為新例外" +"的 :attr:`~BaseException.__context__` 屬性附加:" #: ../../reference/simple_stmts.rst:627 msgid "" @@ -757,7 +923,7 @@ msgstr "" msgid "" "Exception chaining can be explicitly suppressed by specifying :const:`None` " "in the ``from`` clause:" -msgstr "" +msgstr "可以透過在 ``from`` 子句中指定 :const:`None` 來明確抑制例外鏈結:" #: ../../reference/simple_stmts.rst:650 msgid "" @@ -785,6 +951,8 @@ msgid "" "`exceptions`, and information about handling exceptions is in section :ref:" "`try`." msgstr "" +"關於例外的更多資訊可以在\\ :ref:`exceptions`\\ 章節找到,關於處理例外的資訊可" +"以在\\ :ref:`try`\\ 章節找到。" #: ../../reference/simple_stmts.rst:664 msgid ":const:`None` is now permitted as ``Y`` in ``raise X from Y``." @@ -795,6 +963,8 @@ msgid "" "Added the :attr:`~BaseException.__suppress_context__` attribute to suppress " "automatic display of the exception context." msgstr "" +"新增了 :attr:`~BaseException.__suppress_context__` 屬性以抑制例外情境的自動顯" +"示。" #: ../../reference/simple_stmts.rst:670 msgid "" @@ -803,6 +973,8 @@ msgid "" "modified traceback. Previously, the exception was re-raised with the " "traceback it had when it was caught." msgstr "" +"如果活動例外的追蹤在 :keyword:`except` 子句中被修改,則後續的 ``raise`` 陳述" +"式會使用修改後的追蹤重新引發例外。以前,例外會使用它被捕獲時的追蹤重新引發。" #: ../../reference/simple_stmts.rst:679 msgid "The :keyword:`!break` statement" @@ -814,18 +986,23 @@ msgid "" "keyword:`while` loop, but not nested in a function or class definition " "within that loop." msgstr "" +":keyword:`break` 只能在語法上出現在 :keyword:`for` 或 :keyword:`while` 迴圈的" +"巢狀結構中,但不能巢狀在該迴圈內的函式或類別定義中。" #: ../../reference/simple_stmts.rst:697 msgid "" "It terminates the nearest enclosing loop, skipping the optional :keyword:`!" "else` clause if the loop has one." msgstr "" +"它會終止最近的外層迴圈,如果迴圈有可選的 :keyword:`!else` 子句,則會跳過它。" #: ../../reference/simple_stmts.rst:700 msgid "" "If a :keyword:`for` loop is terminated by :keyword:`break`, the loop control " "target keeps its current value." msgstr "" +"如果 :keyword:`for` 迴圈被 :keyword:`break` 終止,迴圈控制目標會保持其當前" +"值。" #: ../../reference/simple_stmts.rst:705 msgid "" @@ -833,6 +1010,8 @@ msgid "" "a :keyword:`finally` clause, that :keyword:`!finally` clause is executed " "before really leaving the loop." msgstr "" +"當 :keyword:`break` 將控制權從帶有 :keyword:`finally` 子句的 :keyword:`try` " +"陳述式中傳出時,該 :keyword:`!finally` 子句會在真正離開迴圈之前被執行。" #: ../../reference/simple_stmts.rst:713 msgid "The :keyword:`!continue` statement" @@ -845,6 +1024,9 @@ msgid "" "within that loop. It continues with the next cycle of the nearest enclosing " "loop." msgstr "" +":keyword:`continue` 在語法上只能出現於 :keyword:`for` 或 :keyword:`while` 迴" +"圈的巢狀結構中,但不能在該迴圈內的函式或類別定義中。它會繼續執行最近外層迴" +"圈的下一個循環。" #: ../../reference/simple_stmts.rst:729 msgid "" @@ -852,6 +1034,9 @@ msgid "" "with a :keyword:`finally` clause, that :keyword:`!finally` clause is " "executed before really starting the next loop cycle." msgstr "" +"當 :keyword:`continue` 將控制權從帶有 :keyword:`finally` 子句" +"的 :keyword:`try` 陳述式中傳出時,該 :keyword:`!finally` 子句會在真正開始下一" +"個迴圈循環之前被執行。" #: ../../reference/simple_stmts.rst:738 msgid "The :keyword:`!import` statement" @@ -861,17 +1046,18 @@ msgstr ":keyword:`!import` 陳述式" msgid "" "The basic import statement (no :keyword:`from` clause) is executed in two " "steps:" -msgstr "" +msgstr "基本的 import 陳述式(不含 :keyword:`from` 子句)分兩個步驟執行:" #: ../../reference/simple_stmts.rst:762 msgid "find a module, loading and initializing it if necessary" -msgstr "" +msgstr "找到一個模組,如有必要則載入並初始化它" #: ../../reference/simple_stmts.rst:763 msgid "" "define a name or names in the local namespace for the scope where the :" "keyword:`import` statement occurs." msgstr "" +"在 :keyword:`import` 陳述式出現的作用域的區域命名空間中定義一個或多個名稱。" #: ../../reference/simple_stmts.rst:766 msgid "" @@ -879,6 +1065,8 @@ msgid "" "steps are carried out separately for each clause, just as though the clauses " "had been separated out into individual import statements." msgstr "" +"當陳述式包含多個子句(以逗號分隔)時,這兩個步驟會分別對每個子句執行,就像這" +"些子句被分離成單獨的 import 陳述式一樣。" #: ../../reference/simple_stmts.rst:771 msgid "" @@ -890,18 +1078,24 @@ msgid "" "could not be located, *or* that an error occurred while initializing the " "module, which includes execution of the module's code." msgstr "" +"第一步(尋找和載入模組)的詳細資訊在\\ :ref:`引入系統 `\\ 章節" +"中有更詳細的描述,該章節還描述了可以引入的各種套件和模組型別,以及所有可用於" +"自訂引入系統的掛鉤 (hook)。請注意,此步驟的失敗可能表示找不到模組,\\ *或者" +"*\\ 在初始化模組時發生錯誤,這包括執行模組的程式碼。" #: ../../reference/simple_stmts.rst:779 msgid "" "If the requested module is retrieved successfully, it will be made available " "in the local namespace in one of three ways:" -msgstr "" +msgstr "如果請求的模組被成功取得,它將透過以下三種方式之一在區域命名空間中可用:" #: ../../reference/simple_stmts.rst:784 msgid "" "If the module name is followed by :keyword:`!as`, then the name following :" "keyword:`!as` is bound directly to the imported module." msgstr "" +"如果模組名稱後面跟著 :keyword:`!as`,則 :keyword:`!as` 後面的名稱會直接繫結到" +"被引入的模組。" #: ../../reference/simple_stmts.rst:786 msgid "" @@ -909,6 +1103,8 @@ msgid "" "module, the module's name is bound in the local namespace as a reference to " "the imported module" msgstr "" +"如果沒有指定其他名稱,且被引入的模組是頂層模組,則模組的名稱會在區域命名空間" +"中繫結為被引入模組的參照" #: ../../reference/simple_stmts.rst:789 msgid "" @@ -917,34 +1113,38 @@ msgid "" "namespace as a reference to the top level package. The imported module must " "be accessed using its full qualified name rather than directly" msgstr "" +"如果被引入的模組\\ *不是*\\ 頂層模組,則包含該模組的頂層套件的名稱會在區域命" +"名空間中繫結為頂層套件的參照。被引入的模組必須使用其完整的限定名稱來存取,而" +"不是直接存取" #: ../../reference/simple_stmts.rst:799 msgid "The :keyword:`from` form uses a slightly more complex process:" -msgstr "" +msgstr ":keyword:`from` 形式使用稍微複雜一點的過程:" #: ../../reference/simple_stmts.rst:801 msgid "" "find the module specified in the :keyword:`from` clause, loading and " "initializing it if necessary;" -msgstr "" +msgstr "找到 :keyword:`from` 子句中指定的模組,如有必要則載入並初始化它;" #: ../../reference/simple_stmts.rst:803 msgid "for each of the identifiers specified in the :keyword:`import` clauses:" -msgstr "" +msgstr "對於 :keyword:`import` 子句中指定的每個識別字:" #: ../../reference/simple_stmts.rst:805 msgid "check if the imported module has an attribute by that name" -msgstr "" +msgstr "檢查被引入的模組是否有該名稱的屬性" #: ../../reference/simple_stmts.rst:806 msgid "" "if not, attempt to import a submodule with that name and then check the " "imported module again for that attribute" msgstr "" +"如果沒有,嘗試引入具有該名稱的子模組,然後再次檢查被引入的模組是否有該屬性" #: ../../reference/simple_stmts.rst:808 msgid "if the attribute is not found, :exc:`ImportError` is raised." -msgstr "" +msgstr "如果找不到該屬性,則會引發 :exc:`ImportError`。" #: ../../reference/simple_stmts.rst:809 msgid "" @@ -952,6 +1152,8 @@ msgid "" "the name in the :keyword:`!as` clause if it is present, otherwise using the " "attribute name" msgstr "" +"否則,對該值的參照會儲存在區域命名空間中,如果存在 :keyword:`!as` 子句則使用" +"其中的名稱,否則使用屬性名稱" #: ../../reference/simple_stmts.rst:813 msgid "Examples::" @@ -968,6 +1170,14 @@ msgid "" "baz bound as baz\n" "from foo import attr # foo imported and foo.attr bound as attr" msgstr "" +"import foo # foo 被引入並在本地繫結\n" +"import foo.bar.baz # foo、foo.bar 和 foo.bar.baz 被引入,foo 在本地繫" +"結\n" +"import foo.bar.baz as fbb # foo、foo.bar 和 foo.bar.baz 被引入,foo.bar.baz " +"繫結為 fbb\n" +"from foo.bar import baz # foo、foo.bar 和 foo.bar.baz 被引入,foo.bar.baz " +"繫結為 baz\n" +"from foo import attr # foo 被引入,foo.attr 繫結為 attr" #: ../../reference/simple_stmts.rst:823 msgid "" @@ -975,6 +1185,8 @@ msgid "" "defined in the module are bound in the local namespace for the scope where " "the :keyword:`import` statement occurs." msgstr "" +"如果識別字串列被星號(``'*'``)取代,則模組中定義的所有公開名稱都會" +"在 :keyword:`import` 陳述式出現的作用域的區域命名空間中繫結。" #: ../../reference/simple_stmts.rst:832 msgid "" @@ -990,6 +1202,13 @@ msgid "" "to avoid accidentally exporting items that are not part of the API (such as " "library modules which were imported and used within the module)." msgstr "" +"模組定義的\\ *公開名稱*\\ 是透過檢查模組命名空間中名為 ``__all__`` 的變數來決" +"定的;如果有定義,它必須是一個字串序列,這些字串是該模組定義或引入的名稱。包" +"含非 ASCII 字元的名稱必須使用 `normalization form`_ NFKC;詳情請參" +"閱 :ref:`lexical-names-nonascii`。``__all__`` 中給出的名稱都被視為公開的,且必" +"須存在。如果 ``__all__`` 沒有定義,公開名稱的集合包括模組命名空間中所有不以底" +"線字元(``'_'``)開頭的名稱。``__all__`` 應該包含整個公開 API。這是為了避免意" +"外匯出不屬於 API 的項目(例如在模組內被引入和使用的函式庫模組)。" #: ../../reference/simple_stmts.rst:844 msgid "" @@ -997,6 +1216,8 @@ msgid "" "allowed at the module level. Attempting to use it in class or function " "definitions will raise a :exc:`SyntaxError`." msgstr "" +"萬用字元形式的引入——``from module import *``——只允許在模組層級使用。嘗試在類" +"別或函式定義中使用它會引發 :exc:`SyntaxError`。" #: ../../reference/simple_stmts.rst:851 msgid "" @@ -1014,12 +1235,22 @@ msgid "" "``pkg.subpkg2.mod``. The specification for relative imports is contained in " "the :ref:`relativeimports` section." msgstr "" +"在指定要引入的模組時,你不必指定模組的絕對名稱。當一個模組或套件包含在另一個" +"套件中時,可以在同一個頂層套件內進行相對引入,而不必提及套件名稱。透過" +"在 :keyword:`from` 後面的指定模組或套件中使用前導點,你可以指定要向上遍歷當前" +"套件階層結構多高,而不必指定確切的名稱。一個前導點表示進行引入的模組所在的當" +"前套件。兩個點表示向上一個套件層級。三個點表示向上兩個層級,依此類推。因此," +"如果你從 ``pkg`` 套件中的模組執行 ``from . import mod``,你最終會引入 " +"``pkg.mod``。如果你從 ``pkg.subpkg1`` 內部執行 ``from ..subpkg2 import " +"mod``,你會引入 ``pkg.subpkg2.mod``。相對引入的規格說明包含在" +"\\ :ref:`relativeimports`\\ 章節中。" #: ../../reference/simple_stmts.rst:865 msgid "" ":func:`importlib.import_module` is provided to support applications that " "determine dynamically the modules to be loaded." msgstr "" +":func:`importlib.import_module` 用於支援需要動態決定載入模組的應用程式。" #: ../../reference/simple_stmts.rst:868 msgid "" @@ -1032,7 +1263,7 @@ msgstr "" #: ../../reference/simple_stmts.rst:875 msgid "Future statements" -msgstr "" +msgstr "Future 陳述式" #: ../../reference/simple_stmts.rst:881 msgid "" @@ -1040,6 +1271,9 @@ msgid "" "module should be compiled using syntax or semantics that will be available " "in a specified future release of Python where the feature becomes standard." msgstr "" +":dfn:`future 陳述式 (future statement)`\\ 是給編譯器的指令,表示特定模組應該" +"使用將在 Python 的指定未來版本(該功能成為標準的版本)中可用的語法或語義來編" +"譯。" #: ../../reference/simple_stmts.rst:885 msgid "" @@ -1048,34 +1282,38 @@ msgid "" "of the new features on a per-module basis before the release in which the " "feature becomes standard." msgstr "" +"future 陳述式旨在簡化向 Python 未來版本的遷移,這些版本引入了語言的不相容變" +"更。它允許在該功能成為標準的版本發佈之前,以每個模組為基礎使用新功能。" #: ../../reference/simple_stmts.rst:897 msgid "" "A future statement must appear near the top of the module. The only lines " "that can appear before a future statement are:" msgstr "" +"future 陳述式必須出現在模組的頂部附近。可以出現在 future 陳述式之前的行只有:" #: ../../reference/simple_stmts.rst:900 msgid "the module docstring (if any)," -msgstr "" +msgstr "模組的文件字串(如果有的話)," #: ../../reference/simple_stmts.rst:901 msgid "comments," -msgstr "" +msgstr "註解," #: ../../reference/simple_stmts.rst:902 msgid "blank lines, and" -msgstr "" +msgstr "空白行,以及" #: ../../reference/simple_stmts.rst:903 msgid "other future statements." -msgstr "" +msgstr "其他 future 陳述式。" #: ../../reference/simple_stmts.rst:905 msgid "" "The only feature that requires using the future statement is ``annotations`` " "(see :pep:`563`)." msgstr "" +"唯一需要使用 future 陳述式的功能是 ``annotations``\\ (請參閱 :pep:`563`)。" #: ../../reference/simple_stmts.rst:908 msgid "" @@ -1086,6 +1324,11 @@ msgid "" "redundant because they are always enabled, and only kept for backwards " "compatibility." msgstr "" +"所有透過 future 陳述式啟用的歷史功能仍被 Python 3 識別。這些功能包括 " +"``absolute_import``、``division``、``generators``、``generator_stop``、" +"``unicode_literals``、``print_function``、``nested_scopes`` 和 " +"``with_statement``。它們都是多餘的,因為它們總是被啟用的,只是為了向後相容性" +"而保留。" #: ../../reference/simple_stmts.rst:915 msgid "" @@ -1096,6 +1339,10 @@ msgid "" "case the compiler may need to parse the module differently. Such decisions " "cannot be pushed off until runtime." msgstr "" +"future 陳述式在編譯時被識別並特別處理:對核心構造語義的變更通常透過產生不同的" +"程式碼來實作。甚至可能出現新功能引入不相容語法(例如新的保留字)的情況,在這" +"種情況下,編譯器可能需要以不同的方式剖析模組。這些決定無法延遲到 runtime 才做" +"出。" #: ../../reference/simple_stmts.rst:922 msgid "" @@ -1103,6 +1350,8 @@ msgid "" "defined, and raises a compile-time error if a future statement contains a " "feature not known to it." msgstr "" +"對於任何給定的版本,編譯器知道哪些功能名稱已被定義,如果 future 陳述式包含它" +"不認識的功能,則會引發編譯時錯誤。" #: ../../reference/simple_stmts.rst:926 msgid "" @@ -1110,16 +1359,19 @@ msgid "" "is a standard module :mod:`__future__`, described later, and it will be " "imported in the usual way at the time the future statement is executed." msgstr "" +"直接的 runtime 語義與任何 import 陳述式相同:有一個標準模" +"組 :mod:`__future__`\\ (稍後描述),它會在 future 陳述式執行時以通常的方式被" +"引入。" #: ../../reference/simple_stmts.rst:930 msgid "" "The interesting runtime semantics depend on the specific feature enabled by " "the future statement." -msgstr "" +msgstr "有趣的 runtime 語義取決於 future 陳述式啟用的特定功能。" #: ../../reference/simple_stmts.rst:933 msgid "Note that there is nothing special about the statement::" -msgstr "" +msgstr "請注意,以下陳述式沒有什麼特別的: ::" #: ../../reference/simple_stmts.rst:935 msgid "import __future__ [as name]" @@ -1130,6 +1382,8 @@ msgid "" "That is not a future statement; it's an ordinary import statement with no " "special semantics or syntax restrictions." msgstr "" +"這不是 future 陳述式;它是一個普通的 import 陳述式,沒有特殊的語義或語法限" +"制。" #: ../../reference/simple_stmts.rst:940 msgid "" @@ -1139,6 +1393,9 @@ msgid "" "statement. This can be controlled by optional arguments to :func:`compile` " "--- see the documentation of that function for details." msgstr "" +"在包含 future 陳述式的模組 :mod:`!M` 中,透過呼叫內建函式 :func:`exec` " +"和 :func:`compile` 編譯的程式碼預設會使用與 future 陳述式相關的新語法或語義。" +"這可以透過 :func:`compile` 的可選引數來控制——詳情請參閱該函式的文件。" #: ../../reference/simple_stmts.rst:946 msgid "" @@ -1148,14 +1405,17 @@ msgid "" "and the script includes a future statement, it will be in effect in the " "interactive session started after the script is executed." msgstr "" +"在互動式直譯器提示字元下輸入的 future 陳述式會在直譯器工作階段的其餘部分生" +"效。如果直譯器使用 :option:`-i` 選項啟動,傳入一個要執行的腳本名稱,且該腳本" +"包含 future 陳述式,則它會在腳本執行後啟動的互動式工作階段中生效。" #: ../../reference/simple_stmts.rst:954 msgid ":pep:`236` - Back to the __future__" -msgstr "" +msgstr ":pep:`236` - 回到 __future__" #: ../../reference/simple_stmts.rst:955 msgid "The original proposal for the __future__ mechanism." -msgstr "" +msgstr "__future__ 機制的原始提案。" #: ../../reference/simple_stmts.rst:961 msgid "The :keyword:`!global` statement" @@ -1168,6 +1428,9 @@ msgid "" "variable without :keyword:`!global`, although free variables may refer to " "globals without being declared global." msgstr "" +":keyword:`global` 陳述式會使列出的識別字被解釋為全域變數。如果沒" +"有 :keyword:`!global`,就不可能對全域變數進行賦值,儘管自由變數可以在未被宣告" +"為 global 的情況下參照全域變數。" #: ../../reference/simple_stmts.rst:976 msgid "" @@ -1176,6 +1439,9 @@ msgid "" "if a variable is used or assigned to prior to its global declaration in the " "scope." msgstr "" +":keyword:`!global` 陳述式適用於整個當前作用域(模組、函式主體或類別定義)。如" +"果在該作用域中,變數在其 global 宣告之前被使用或賦值,則會引" +"發 :exc:`SyntaxError`。" #: ../../reference/simple_stmts.rst:981 msgid "" @@ -1184,6 +1450,9 @@ msgid "" "assigned to prior to their :keyword:`!global` declaration. This requirement " "is relaxed in the interactive prompt (:term:`REPL`)." msgstr "" +"在模組層級,所有變數都是全域的,因此 :keyword:`!global` 陳述式沒有效果。然" +"而,變數仍然不能在其 :keyword:`!global` 宣告之前被使用或賦值。這個要求在互動" +"式提示符(:term:`REPL`)中被放寬。" #: ../../reference/simple_stmts.rst:992 msgid "" @@ -1196,6 +1465,12 @@ msgid "" "containing the function call. The same applies to the :func:`eval` and :" "func:`compile` functions." msgstr "" +"**程式設計師注意事項:**\\ :keyword:`global` 是給剖析器的指令。它只適用於" +"與 :keyword:`!global` 陳述式同時被剖析的程式碼。特別是,包含在提供給內" +"建 :func:`exec` 函式的字串或程式碼物件中的 :keyword:`!global` 陳述式不會影響" +"\\ *包含*\\ 該函式呼叫的程式碼區塊,而且這種字串中包含的程式碼不受包含函式呼" +"叫的程式碼中的 :keyword:`!global` 陳述式影響。同樣的規則也適用" +"於 :func:`eval` 和 :func:`compile` 函式。" #: ../../reference/simple_stmts.rst:1004 msgid "The :keyword:`!nonlocal` statement" @@ -1212,6 +1487,11 @@ msgid "" "not bound in any nonlocal scope, or if there is no nonlocal scope, a :exc:" "`SyntaxError` is raised." msgstr "" +"當函式或類別的定義巢狀(封閉)在其他函式的定義內時,它的非區域作用域就是外層" +"函式的區域作用域。:keyword:`nonlocal` 陳述式會使列出的識別字參照先前在非區域" +"作用域中繫結的名稱。它允許被封裝的程式碼重新繫結這些非區域識別字。如果一個名" +"稱在多個非區域作用域中被繫結,則使用最近的繫結。如果一個名稱在任何非區域作用" +"域中都沒有被繫結,或者沒有非區域作用域,則會引發 :exc:`SyntaxError`。" #: ../../reference/simple_stmts.rst:1021 msgid "" @@ -1219,14 +1499,16 @@ msgid "" "or class body. A :exc:`SyntaxError` is raised if a variable is used or " "assigned to prior to its nonlocal declaration in the scope." msgstr "" +":keyword:`nonlocal` 陳述式適用於函式或類別主體的整個作用域。如果在該作用域" +"中,變數在其 nonlocal 宣告之前被使用或賦值,則會引發 :exc:`SyntaxError`。" #: ../../reference/simple_stmts.rst:1027 msgid ":pep:`3104` - Access to Names in Outer Scopes" -msgstr "" +msgstr ":pep:`3104` - 存取外層作用域中的名稱" #: ../../reference/simple_stmts.rst:1028 msgid "The specification for the :keyword:`nonlocal` statement." -msgstr "" +msgstr ":keyword:`nonlocal` 陳述式的規格說明。" #: ../../reference/simple_stmts.rst:1030 msgid "" @@ -1234,6 +1516,8 @@ msgid "" "applies only to code parsed along with it. See the note for the :keyword:" "`global` statement." msgstr "" +"**程式設計師注意事項:**\\ :keyword:`nonlocal` 是給剖析器的指令,只適用於與它" +"一起被剖析的程式碼。請參閱 :keyword:`global` 陳述式的注意事項。" #: ../../reference/simple_stmts.rst:1038 msgid "The :keyword:`!type` statement" @@ -1244,18 +1528,20 @@ msgid "" "The :keyword:`!type` statement declares a type alias, which is an instance " "of :class:`typing.TypeAliasType`." msgstr "" +":keyword:`!type` 陳述式宣告一個型別別名,它是 :class:`typing.TypeAliasType` " +"的實例。" #: ../../reference/simple_stmts.rst:1048 msgid "For example, the following statement creates a type alias::" -msgstr "" +msgstr "例如以下陳述式建立了一個型別別名: ::" #: ../../reference/simple_stmts.rst:1050 msgid "type Point = tuple[float, float]" -msgstr "" +msgstr "type Point = tuple[float, float]" #: ../../reference/simple_stmts.rst:1052 msgid "This code is roughly equivalent to::" -msgstr "" +msgstr "這段程式碼大致等價於: ::" #: ../../reference/simple_stmts.rst:1054 msgid "" @@ -1263,12 +1549,17 @@ msgid "" " return tuple[float, float]\n" "Point = typing.TypeAliasType(\"Point\", VALUE_OF_Point())" msgstr "" +"annotation-def VALUE_OF_Point():\n" +" return tuple[float, float]\n" +"Point = typing.TypeAliasType(\"Point\", VALUE_OF_Point())" #: ../../reference/simple_stmts.rst:1058 msgid "" "``annotation-def`` indicates an :ref:`annotation scope `, " "which behaves mostly like a function, but with several small differences." msgstr "" +"``annotation-def`` 表示一個\\ :ref:`註釋作用域 `,它的行為" +"大部分像函式,但有一些小差異。" #: ../../reference/simple_stmts.rst:1061 msgid "" @@ -1278,30 +1569,35 @@ msgid "" "`lazy-evaluation`). This allows the type alias to refer to names that are " "not yet defined." msgstr "" +"型別別名的值在註釋作用域中被求值。它不是在型別別名建立時求值,而是只有在透過" +"型別別名的 :attr:`!__value__` 屬性存取該值時才求值(請參閱\\ :ref:`lazy-" +"evaluation`)。這允許型別別名參照尚未定義的名稱。" #: ../../reference/simple_stmts.rst:1067 msgid "" "Type aliases may be made generic by adding a :ref:`type parameter list ` after the name. See :ref:`generic-type-aliases` for more." msgstr "" +"型別別名可以透過在名稱後面新增\\ :ref:`型別參數串列 `\\ 來使其成" +"為泛型。更多資訊請參閱\\ :ref:`generic-type-aliases`。" #: ../../reference/simple_stmts.rst:1070 msgid ":keyword:`!type` is a :ref:`soft keyword `." -msgstr "" +msgstr ":keyword:`!type` 是一個\\ :ref:`軟關鍵字 `。" #: ../../reference/simple_stmts.rst:1076 msgid ":pep:`695` - Type Parameter Syntax" -msgstr "" +msgstr ":pep:`695` - 型別參數語法" #: ../../reference/simple_stmts.rst:1077 msgid "" "Introduced the :keyword:`!type` statement and syntax for generic classes and " "functions." -msgstr "" +msgstr "引入了 :keyword:`!type` 陳述式以及泛型類別和函式的語法。" #: ../../reference/simple_stmts.rst:8 msgid "simple" -msgstr "" +msgstr "simple(簡單)" #: ../../reference/simple_stmts.rst:8 ../../reference/simple_stmts.rst:39 #: ../../reference/simple_stmts.rst:75 ../../reference/simple_stmts.rst:258 @@ -1318,7 +1614,7 @@ msgstr "statement(陳述式)" #: ../../reference/simple_stmts.rst:39 ../../reference/simple_stmts.rst:42 msgid "expression" -msgstr "" +msgstr "expression(運算式)" #: ../../reference/simple_stmts.rst:39 ../../reference/simple_stmts.rst:42 #: ../../reference/simple_stmts.rst:104 ../../reference/simple_stmts.rst:115 @@ -1354,27 +1650,27 @@ msgstr "conversion" #: ../../reference/simple_stmts.rst:56 msgid "output" -msgstr "" +msgstr "output(輸出)" #: ../../reference/simple_stmts.rst:56 msgid "standard" -msgstr "" +msgstr "standard(標準)" #: ../../reference/simple_stmts.rst:56 msgid "writing" -msgstr "" +msgstr "writing(寫入)" #: ../../reference/simple_stmts.rst:56 msgid "values" -msgstr "" +msgstr "values(值)" #: ../../reference/simple_stmts.rst:56 msgid "procedure" -msgstr "" +msgstr "procedure(程序)" #: ../../reference/simple_stmts.rst:56 msgid "call" -msgstr "" +msgstr "call(呼叫)" #: ../../reference/simple_stmts.rst:75 msgid "= (equals)" @@ -1428,7 +1724,7 @@ msgstr ", (逗號)" #: ../../reference/simple_stmts.rst:115 msgid "in target list" -msgstr "於目標列表中" +msgstr "於目標串列中" #: ../../reference/simple_stmts.rst:115 ../../reference/simple_stmts.rst:821 msgid "* (asterisk)" @@ -1436,7 +1732,7 @@ msgstr "* (星號)" #: ../../reference/simple_stmts.rst:115 msgid "in assignment target list" -msgstr "於賦值目標列表中" +msgstr "於賦值目標串列中" #: ../../reference/simple_stmts.rst:115 msgid "[] (square brackets)" @@ -1560,7 +1856,7 @@ msgstr "assertions(斷言)" #: ../../reference/simple_stmts.rst:379 msgid "expression list" -msgstr "expression list(運算式列表)" +msgstr "expression list(運算式串列)" #: ../../reference/simple_stmts.rst:400 msgid "__debug__" @@ -1774,4 +2070,4 @@ msgstr "nonlocal" #: ../../reference/simple_stmts.rst:1040 msgid "type" -msgstr "" +msgstr "type(型別)"