diff --git a/tutorial/classes.po b/tutorial/classes.po index 1a71fad46f..c1284d3f93 100644 --- a/tutorial/classes.po +++ b/tutorial/classes.po @@ -375,6 +375,28 @@ msgid "" "scope_test()\n" "print(\"In global scope:\", spam)" msgstr "" +"def scope_test():\n" +" def do_local():\n" +" spam = \"local spam\"\n" +"\n" +" def do_nonlocal():\n" +" nonlocal spam\n" +" spam = \"nonlocal spam\"\n" +"\n" +" def do_global():\n" +" global spam\n" +" spam = \"global spam\"\n" +"\n" +" spam = \"test spam\"\n" +" do_local()\n" +" print(\"After local assignment:\", spam)\n" +" do_nonlocal()\n" +" print(\"After nonlocal assignment:\", spam)\n" +" do_global()\n" +" print(\"After global assignment:\", spam)\n" +"\n" +"scope_test()\n" +"print(\"In global scope:\", spam)" #: ../../tutorial/classes.rst:191 msgid "The output of the example code is:" @@ -387,6 +409,10 @@ msgid "" "After global assignment: nonlocal spam\n" "In global scope: global spam" msgstr "" +"After local assignment: test spam\n" +"After nonlocal assignment: nonlocal spam\n" +"After global assignment: nonlocal spam\n" +"In global scope: global spam" #: ../../tutorial/classes.rst:200 msgid "" @@ -665,6 +691,7 @@ msgid "" "The other kind of instance attribute reference is a *method*. A method is a " "function that \"belongs to\" an object." msgstr "" +"另一種執行個體屬性參考是 *方法* (method)。方法是\"屬於\"一個物件的函式。" #: ../../tutorial/classes.rst:345 msgid "" @@ -795,6 +822,23 @@ msgid "" ">>> e.name # unique to e\n" "'Buddy'" msgstr "" +"class Dog:\n" +"\n" +" kind = 'canine' # 所有實例共享的類別變數\n" +"\n" +" def __init__(self, name):\n" +" self.name = name # 每個實例獨有的實例變數\n" +"\n" +">>> d = Dog('Fido')\n" +">>> e = Dog('Buddy')\n" +">>> d.kind # 為所有 Dog 實例所共享\n" +"'canine'\n" +">>> e.kind # 為所有 Dog 實例所共享\n" +"'canine'\n" +">>> d.name # d 獨有\n" +"'Fido'\n" +">>> e.name # e 獨有\n" +"'Buddy'" #: ../../tutorial/classes.rst:422 msgid "" @@ -1363,6 +1407,24 @@ msgid "" " for item in zip(keys, values):\n" " self.items_list.append(item)" msgstr "" +"class Mapping:\n" +" def __init__(self, iterable):\n" +" self.items_list = []\n" +" self.__update(iterable)\n" +"\n" +" def update(self, iterable):\n" +" for item in iterable:\n" +" self.items_list.append(item)\n" +"\n" +" __update = update # 原始 update() 方法的私有副本\n" +"\n" +"class MappingSubclass(Mapping):\n" +"\n" +" def update(self, keys, values):\n" +" # 為 update() 提供新的函式簽名\n" +" # 但不會破壞 __init__()\n" +" for item in zip(keys, values):\n" +" self.items_list.append(item)" #: ../../tutorial/classes.rst:718 msgid "" @@ -1592,6 +1654,20 @@ msgid "" " self.index = self.index - 1\n" " return self.data[self.index]" msgstr "" +"class Reverse:\n" +" \"\"\"用於向後迴圈遍歷序列的疊代器。\"\"\"\n" +" def __init__(self, data):\n" +" self.data = data\n" +" self.index = len(data)\n" +"\n" +" def __iter__(self):\n" +" return self\n" +"\n" +" def __next__(self):\n" +" if self.index == 0:\n" +" raise StopIteration\n" +" self.index = self.index - 1\n" +" return self.data[self.index]" #: ../../tutorial/classes.rst:845 msgid "" @@ -1737,6 +1813,22 @@ msgid "" ">>> list(data[i] for i in range(len(data)-1, -1, -1))\n" "['f', 'l', 'o', 'g']" msgstr "" +">>> sum(i*i for i in range(10)) # 平方和\n" +"285\n" +"\n" +">>> xvec = [10, 20, 30]\n" +">>> yvec = [7, 5, 3]\n" +">>> sum(x*y for x,y in zip(xvec, yvec)) # 向量內積\n" +"260\n" +"\n" +">>> unique_words = set(word for line in page for word in line.split())\n" +"\n" +">>> valedictorian = max((student.gpa, student.name) for student in " +"graduates)\n" +"\n" +">>> data = 'golf'\n" +">>> list(data[i] for i in range(len(data)-1, -1, -1))\n" +"['f', 'l', 'o', 'g']" #: ../../tutorial/classes.rst:932 msgid "Footnotes" diff --git a/tutorial/controlflow.po b/tutorial/controlflow.po index fd2ee89755..5f29a00603 100644 --- a/tutorial/controlflow.po +++ b/tutorial/controlflow.po @@ -59,6 +59,19 @@ msgid "" "...\n" "More" msgstr "" +">>> x = int(input(\"Please enter an integer: \"))\n" +"Please enter an integer: 42\n" +">>> if x < 0:\n" +"... x = 0\n" +"... print('Negative changed to zero')\n" +"... elif x == 0:\n" +"... print('Zero')\n" +"... elif x == 1:\n" +"... print('Single')\n" +"... else:\n" +"... print('More')\n" +"...\n" +"More" #: ../../tutorial/controlflow.rst:33 msgid "" @@ -112,6 +125,14 @@ msgid "" "window 6\n" "defenestrate 12" msgstr "" +">>> # 測量一些字串:\n" +">>> words = ['cat', 'window', 'defenestrate']\n" +">>> for w in words:\n" +"... print(w, len(w))\n" +"...\n" +"cat 3\n" +"window 6\n" +"defenestrate 12" #: ../../tutorial/controlflow.rst:72 msgid "" @@ -138,6 +159,19 @@ msgid "" " if status == 'active':\n" " active_users[user] = status" msgstr "" +"# 建立一個範例集合\n" +"users = {'Hans': 'active', 'Éléonore': 'inactive', '景太郎': 'active'}\n" +"\n" +"# 策略:對副本進行疊代\n" +"for user, status in users.copy().items():\n" +" if status == 'inactive':\n" +" del users[user]\n" +"\n" +"# 策略:建立一個新集合\n" +"active_users = {}\n" +"for user, status in users.items():\n" +" if status == 'active':\n" +" active_users[user] = status" #: ../../tutorial/controlflow.rst:94 msgid "The :func:`range` Function" @@ -376,6 +410,9 @@ msgid "" "finishes without executing the :keyword:`!break`, the :keyword:`!else` " "clause executes." msgstr "" +"在 :keyword:`!for` 或 :keyword:`!while` 迴圈中,:keyword:`!break` " +"陳述句可能與 :keyword:`!else` 子句配對。如果迴圈完成而沒有執行 " +":keyword:`!break`,:keyword:`!else` 子句會被執行。" #: ../../tutorial/controlflow.rst:208 msgid "" @@ -427,6 +464,23 @@ msgid "" "8 equals 2 * 4\n" "9 equals 3 * 3" msgstr "" +">>> for n in range(2, 10):\n" +"... for x in range(2, n):\n" +"... if n % x == 0:\n" +"... print(n, 'equals', x, '*', n//x)\n" +"... break\n" +"... else:\n" +"... # 迴圈結束但沒有找到因數\n" +"... print(n, 'is a prime number')\n" +"...\n" +"2 is a prime number\n" +"3 is a prime number\n" +"4 equals 2 * 2\n" +"5 is a prime number\n" +"6 equals 2 * 3\n" +"7 is a prime number\n" +"8 equals 2 * 4\n" +"9 equals 3 * 3" #: ../../tutorial/controlflow.rst:239 msgid "" @@ -444,6 +498,9 @@ msgid "" "condition is ever true, a ``break`` will happen. If the condition is never " "true, the ``else`` clause outside the loop will execute." msgstr "" +"理解 else 子句的一個方法是將它想像成與迴圈內的 ``if`` 配對。當迴圈執行時,它會" +"運行如 if/if/if/else 的序列。``if`` 在迴圈內,會遇到多次。如果條件曾經為真," +"``break`` 就會發生。如果條件從未為真,迴圈外的 ``else`` 子句就會執行。" #: ../../tutorial/controlflow.rst:248 msgid "" @@ -478,6 +535,9 @@ msgid "" "... pass # Busy-wait for keyboard interrupt (Ctrl+C)\n" "..." msgstr "" +">>> while True:\n" +"... pass # 忙碌等待鍵盤中斷 (Ctrl+C)\n" +"..." #: ../../tutorial/controlflow.rst:266 msgid "This is commonly used for creating minimal classes::" @@ -509,6 +569,9 @@ msgid "" "... pass # Remember to implement this!\n" "..." msgstr "" +">>> def initlog(*args):\n" +"... pass # 記得要實作這個!\n" +"..." #: ../../tutorial/controlflow.rst:284 msgid ":keyword:`!match` Statements" @@ -604,6 +667,18 @@ msgid "" " case _:\n" " raise ValueError(\"Not a point\")" msgstr "" +"# point 是一個 (x, y) 元組\n" +"match point:\n" +" case (0, 0):\n" +" print(\"Origin\")\n" +" case (0, y):\n" +" print(f\"Y={y}\")\n" +" case (x, 0):\n" +" print(f\"X={x}\")\n" +" case (x, y):\n" +" print(f\"X={x}, Y={y}\")\n" +" case _:\n" +" raise ValueError(\"Not a point\")" #: ../../tutorial/controlflow.rst:331 msgid "" @@ -912,6 +987,17 @@ msgid "" ">>> fib(2000)\n" "0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597" msgstr "" +">>> def fib(n): # 寫出小於 n 的費氏數列\n" +"... \"\"\"印出小於 n 的費氏數列。\"\"\"\n" +"... a, b = 0, 1\n" +"... while a < n:\n" +"... print(a, end=' ')\n" +"... a, b = b, a+b\n" +"... print()\n" +"...\n" +">>> # 現在呼叫我們剛才定義的函式:\n" +">>> fib(2000)\n" +"0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597" #: ../../tutorial/controlflow.rst:482 msgid "" @@ -1045,6 +1131,18 @@ msgid "" ">>> f100 # write the result\n" "[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]" msgstr "" +">>> def fib2(n): # 回傳到 n 為止的費氏數列\n" +"... \"\"\"回傳包含到 n 為止的費氏數列的串列。\"\"\"\n" +"... result = []\n" +"... a, b = 0, 1\n" +"... while a < n:\n" +"... result.append(a) # 見下方\n" +"... a, b = b, a+b\n" +"... return result\n" +"...\n" +">>> f100 = fib2(100) # 呼叫它\n" +">>> f100 # 寫出結果\n" +"[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]" #: ../../tutorial/controlflow.rst:550 msgid "This example, as usual, demonstrates some new Python features:" @@ -1301,6 +1399,12 @@ msgid "" "parrot('a thousand', state='pushing up the daisies') # 1 positional, 1 " "keyword" msgstr "" +"parrot(1000) # 1 個位置引數\n" +"parrot(voltage=1000) # 1 個關鍵字引數\n" +"parrot(voltage=1000000, action='VOOOOOM') # 2 個關鍵字引數\n" +"parrot(action='VOOOOOM', voltage=1000000) # 2 個關鍵字引數\n" +"parrot('a million', 'bereft of life', 'jump') # 3 個位置引數\n" +"parrot('a thousand', state='pushing up the daisies') # 1 個位置引數、1 個關鍵字引數\n" #: ../../tutorial/controlflow.rst:677 msgid "but all the following calls would be invalid::" @@ -1314,6 +1418,10 @@ msgid "" "parrot(110, voltage=220) # duplicate value for the same argument\n" "parrot(actor='John Cleese') # unknown keyword argument" msgstr "" +"parrot() # 缺少必要引數\n" +"parrot(voltage=5.0, 'dead') # 關鍵字引數後面的非關鍵字引數\n" +"parrot(110, voltage=220) # 同一個引數有重複值\n" +"parrot(actor='John Cleese') # 未知的關鍵字引數" #: ../../tutorial/controlflow.rst:684 msgid "" @@ -1877,6 +1985,11 @@ msgid "" "list\n" "[3, 4, 5]" msgstr "" +">>> list(range(3, 6)) # 使用分離引數的一般呼叫\n" +"[3, 4, 5]\n" +">>> args = [3, 6]\n" +">>> list(range(*args)) # 以從串列解包而得的引數呼叫\n" +"[3, 4, 5]" #: ../../tutorial/controlflow.rst:965 msgid "" @@ -2041,6 +2154,17 @@ msgid "" "\n" "No, really, it doesn't do anything." msgstr "" +">>> def my_function():\n" +"... \"\"\"不做任何事,但有文件說明。\n" +"...\n" +"... 不,真的,它什麼都不做。\n" +"... \"\"\"\n" +"... pass\n" +"...\n" +">>> print(my_function.__doc__)\n" +"Do nothing, but document it.\n" +"\n" +"No, really, it doesn't do anything." #: ../../tutorial/controlflow.rst:1064 msgid "Function Annotations" diff --git a/tutorial/datastructures.po b/tutorial/datastructures.po index d466df73d1..beab2d6a70 100644 --- a/tutorial/datastructures.po +++ b/tutorial/datastructures.po @@ -457,6 +457,33 @@ msgid "" ">>> [num for elem in vec for num in elem]\n" "[1, 2, 3, 4, 5, 6, 7, 8, 9]" msgstr "" +">>> vec = [-4, -2, 0, 2, 4]\n" +">>> # 建立一個值加倍的新串列\n" +">>> [x*2 for x in vec]\n" +"[-8, -4, 0, 4, 8]\n" +">>> # 過濾串列以排除負數\n" +">>> [x for x in vec if x >= 0]\n" +"[0, 2, 4]\n" +">>> # 對所有元素套用函式\n" +">>> [abs(x) for x in vec]\n" +"[4, 2, 0, 2, 4]\n" +">>> # 對每個元素呼叫方法\n" +">>> freshfruit = [' banana', ' loganberry ', 'passion fruit ']\n" +">>> [weapon.strip() for weapon in freshfruit]\n" +"['banana', 'loganberry', 'passion fruit']\n" +">>> # 建立像 (數字, 平方) 的 2-元組串列\n" +">>> [(x, x**2) for x in range(6)]\n" +"[(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25)]\n" +">>> # 元組必須加上括號,否則會產生錯誤\n" +">>> [x, x**2 for x in range(6)]\n" +" File \"\", line 1\n" +" [x, x**2 for x in range(6)]\n" +" ^^^^^^^\n" +"SyntaxError: did you forget parentheses around the comprehension target?\n" +">>> # flatten a list using a listcomp with two 'for'\n" +">>> vec = [[1,2,3], [4,5,6], [7,8,9]]\n" +">>> [num for elem in vec for num in elem]\n" +"[1, 2, 3, 4, 5, 6, 7, 8, 9]" #: ../../tutorial/datastructures.rst:279 msgid "" @@ -856,6 +883,28 @@ msgid "" ">>> a ^ b # letters in a or b but not both\n" "{'r', 'd', 'b', 'm', 'z', 'l'}" msgstr "" +">>> basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}\n" +">>> print(basket) # 確認重複值已被移除\n" +"{'orange', 'banana', 'pear', 'apple'}\n" +">>> 'orange' in basket # 快速成員測試\n" +"True\n" +">>> 'crabgrass' in basket\n" +"False\n" +"\n" +">>> # 示範對兩個字的唯一字母進行集合運算\n" +">>>\n" +">>> a = set('abracadabra')\n" +">>> b = set('alacazam')\n" +">>> a # a 中的唯一字母\n" +"{'a', 'r', 'b', 'c', 'd'}\n" +">>> a - b # 在 a 中但不在 b 中的字母\n" +"{'r', 'd', 'b'}\n" +">>> a | b # 在 a 或 b 或兩者中的字母\n" +"{'a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'}\n" +">>> a & b # 同時在 a 和 b 中的字母\n" +"{'a', 'c'}\n" +">>> a ^ b # 在 a 或 b 中但不在兩者中的字母\n" +"{'r', 'd', 'b', 'm', 'z', 'l'}" #: ../../tutorial/datastructures.rst:482 msgid "" diff --git a/tutorial/floatingpoint.po b/tutorial/floatingpoint.po index dc13c64d29..1492e25182 100644 --- a/tutorial/floatingpoint.po +++ b/tutorial/floatingpoint.po @@ -215,6 +215,14 @@ msgid "" ">>> repr(math.pi)\n" "'3.141592653589793'" msgstr "" +">>> format(math.pi, '.12g') # 給出 12 個有效位數\n" +"'3.14159265359'\n" +"\n" +">>> format(math.pi, '.2f') # 小數點後給出 2 位數字\n" +"'3.14'\n" +"\n" +">>> repr(math.pi)\n" +"'3.141592653589793'" #: ../../tutorial/floatingpoint.rst:111 msgid "" @@ -492,6 +500,22 @@ msgid "" "digits!\n" "-0.0051575902860057365" msgstr "" +">>> arr = [-0.10430216751806065, -266310978.67179024, 143401161448607.16,\n" +"... -143401161400469.7, 266262841.31058735, -0.003244936839808227]\n" +">>> float(sum(map(Fraction, arr))) # 單次四捨五入的精確加總\n" +"8.042173697819788e-13\n" +">>> math.fsum(arr) # 單次四捨五入\n" +"8.042173697819788e-13\n" +">>> sum(arr) # 在擴展精度中進行多次捨入\n" +"8.042178034628478e-13\n" +">>> total = 0.0\n" +">>> for x in arr:\n" +"... total += x # 在標準精度中進行多次捨入 " +"\n" +"...\n" +">>> total # 直接相加沒有正確的數字 " +"\n" +"-0.0051575902860057365" #: ../../tutorial/floatingpoint.rst:260 msgid "Representation Error" diff --git a/tutorial/index.po b/tutorial/index.po index 151c6493a9..7203f4c06c 100644 --- a/tutorial/index.po +++ b/tutorial/index.po @@ -70,7 +70,6 @@ msgstr "" "作為其擴充用介面語言 (extension language)。" #: ../../tutorial/index.rst:27 -#, fuzzy msgid "" "This tutorial introduces the reader informally to the basic concepts and " "features of the Python language and system. Be aware that it expects you to " @@ -78,9 +77,9 @@ msgid "" "Python interpreter handy for hands-on experience, but all examples are self-" "contained, so the tutorial can be read off-line as well." msgstr "" -"這份教學將簡介 Python 語言與系統的基本概念及功能。除了閱讀之外、實際用 " -"Python 直譯器寫程式跑範例,將有助於學習。但如果只用讀的,也是可行的學習方式," -"因為所有範例的內容皆獨立且完整。" +"這份教學將非常規地介紹 Python 語言與系統的基本概念及功能。請注意,它預期你對程式" +"設計有基本的了解。實際用 Python 直譯器進行實際操作將有助於學習,但所有範例都是" +"獨立完整的,所以這份教學也可以離線閱讀。" #: ../../tutorial/index.rst:33 msgid "" diff --git a/tutorial/interpreter.po b/tutorial/interpreter.po index 5f3f9461b1..3df92a2a1e 100644 --- a/tutorial/interpreter.po +++ b/tutorial/interpreter.po @@ -55,7 +55,6 @@ msgstr "" "python` 是個很常見的另類存放路徑。)" #: ../../tutorial/interpreter.rst:26 -#, fuzzy msgid "" "On Windows machines where you have installed Python from the :ref:`Microsoft " "Store `, the |python_x_dot_y_literal| command will be " @@ -64,9 +63,9 @@ msgid "" "launch Python." msgstr "" "Windows 系統中,從 :ref:`Microsoft Store ` 安裝 Python 後,就" -"可以使用 :file:`python3.12` 命令了。如果安裝了 :ref:`py.exe launcher " -"` ,則可以使用 :file:`py` 命令。請參閱附錄::ref:`setting-" -"envvars`,了解其他啟動 Python 的方式。" +"可以使用 |python_x_dot_y_literal| 命令了。如果安裝了 :ref:`py.exe launcher " +"` ,則可以使用 :file:`py` 命令。請參閱 :ref:`setting-" +"envvars` 了解其他啟動 Python 的方式。" #: ../../tutorial/interpreter.rst:31 msgid "" @@ -222,6 +221,11 @@ msgid "" "...\n" "Be careful not to fall off!" msgstr "" +">>> the_world_is_flat = True\n" +">>> if the_world_is_flat:\n" +"... print(\"Be careful not to fall off!\")\n" +"...\n" +"Be careful not to fall off!" #: ../../tutorial/interpreter.rst:118 msgid "For more on interactive mode, see :ref:`tut-interac`." @@ -275,7 +279,7 @@ msgstr "比如,聲明使用 Windows-1252 編碼,源碼檔案要寫成: ::" #: ../../tutorial/interpreter.rst:150 msgid "# -*- coding: cp1252 -*-" -msgstr "" +msgstr "# -*- coding: cp1252 -*-" #: ../../tutorial/interpreter.rst:152 msgid "" diff --git a/tutorial/introduction.po b/tutorial/introduction.po index 08a3720e9a..fb045519ef 100644 --- a/tutorial/introduction.po +++ b/tutorial/introduction.po @@ -45,6 +45,8 @@ msgid "" "hovering over or tapping a code example), which strips prompts and omits " "output, to copy and paste the input lines into your interpreter." msgstr "" +"你可以使用 \"Copy\" 按鈕(當游標移至程式碼範例上方或點選程式碼範例時,它會出現在右上角)," +"這會去除提示字元並略過輸出,讓你可以複製貼上輸入行到你的直譯器。" #: ../../tutorial/introduction.rst:22 msgid "" @@ -73,6 +75,10 @@ msgid "" " # ... and now a third!\n" "text = \"# This is not a comment because it's inside quotes.\"" msgstr "" +"# 這是第一個註解\n" +"spam = 1 # 這是第二個註解\n" +" # ... 現在是第三個!\n" +"text = \"# 這不是註解,因為它在引號內。\"" #: ../../tutorial/introduction.rst:41 msgid "Using Python as a Calculator" @@ -112,6 +118,14 @@ msgid "" ">>> 8 / 5 # division always returns a floating-point number\n" "1.6" msgstr "" +">>> 2 + 2\n" +"4\n" +">>> 50 - 5*6\n" +"20\n" +">>> (50 - 5*6) / 4\n" +"5.0\n" +">>> 8 / 5 # 除法總是回傳浮點數\n" +"1.6" #: ../../tutorial/introduction.rst:67 msgid "" @@ -144,6 +158,15 @@ msgid "" ">>> 5 * 3 + 2 # floored quotient * divisor + remainder\n" "17" msgstr "" +">>> 17 / 3 # 傳統除法回傳浮點數\n" +"5.666666666666667\n" +">>>\n" +">>> 17 // 3 # 下取整除法捨棄小數部分\n" +"5\n" +">>> 17 % 3 # % 運算子回傳除法的餘數\n" +"2\n" +">>> 5 * 3 + 2 # 下取整商 * 除數 + 餘數\n" +"17" #: ../../tutorial/introduction.rst:85 msgid "" @@ -158,6 +181,10 @@ msgid "" ">>> 2 ** 7 # 2 to the power of 7\n" "128" msgstr "" +">>> 5 ** 2 # 5 的平方\n" +"25\n" +">>> 2 ** 7 # 2 的 7 次方\n" +"128" #: ../../tutorial/introduction.rst:92 msgid "" @@ -194,6 +221,10 @@ msgid "" " File \"\", line 1, in \n" "NameError: name 'n' is not defined" msgstr "" +">>> n # 嘗試存取未定義的變數\n" +"Traceback (most recent call last):\n" +" File \"\", line 1, in \n" +"NameError: name 'n' is not defined" #: ../../tutorial/introduction.rst:108 msgid "" @@ -288,6 +319,12 @@ msgid "" ">>> '1975' # digits and numerals enclosed in quotes are also strings\n" "'1975'" msgstr "" +">>> 'spam eggs' # 單引號\n" +"'spam eggs'\n" +">>> \"Paris rabbit got your back :)! Yay!\" # 雙引號\n" +"'Paris rabbit got your back :)! Yay!'\n" +">>> '1975' # 以引號包含的數字和數值也是字串\n" +"'1975'" #: ../../tutorial/introduction.rst:158 msgid "" @@ -299,7 +336,7 @@ msgstr "" #: ../../tutorial/introduction.rst:161 msgid "" -">>> 'doesn\\'t' # use \\' to escape the single quote...\n" +">>> 'doesn\\'t' # 用 \\' 來跳脫單引號...\n" "\"doesn't\"\n" ">>> \"doesn't\" # ...or use double quotes instead\n" "\"doesn't\"\n" @@ -310,6 +347,16 @@ msgid "" ">>> '\"Isn\\'t,\" they said.'\n" "'\"Isn\\'t,\" they said.'" msgstr "" +">>> 'doesn\\'t' # 用 \\' 來跳脫單引號...\n" +"\"doesn't\"\n" +">>> \"doesn't\" # ...或改用雙引號\n" +"\"doesn't\"\n" +">>> '\"Yes,\" they said.'\n" +"'\"Yes,\" they said.'\n" +">>> \"\\\"Yes,\\\" they said.\"\n" +"'\"Yes,\" they said.'\n" +">>> '\"Isn\\'t,\" they said.'\n" +"'\"Isn\\'t,\" they said.'" #: ../../tutorial/introduction.rst:172 msgid "" @@ -331,6 +378,12 @@ msgid "" "First line.\n" "Second line." msgstr "" +">>> s = 'First line.\\nSecond line.' # \\n 表示換行\n" +">>> s # 沒有 print(),特殊字元會包含在字串中\n" +"'First line.\\nSecond line.'\n" +">>> print(s) # 有 print(),特殊字元會被直譯,所以 \\n 會產生新的一行\n" +"First line.\n" +"Second line." #: ../../tutorial/introduction.rst:183 msgid "" @@ -349,6 +402,11 @@ msgid "" ">>> print(r'C:\\some\\name') # note the r before the quote\n" "C:\\some\\name" msgstr "" +">>> print('C:\\some\\name') # 這裡 \\n 表示換行!\n" +"C:\\some\n" +"ame\n" +">>> print(r'C:\\some\\name') # 注意引號前的 r\n" +"C:\\some\\name" #: ../../tutorial/introduction.rst:193 msgid "" @@ -409,6 +467,9 @@ msgid "" ">>> 3 * 'un' + 'ium'\n" "'unununium'" msgstr "" +">>> # 3 次 'un',接著是 'ium'\n" +">>> 3 * 'un' + 'ium'\n" +"'unununium'" #: ../../tutorial/introduction.rst:222 msgid "" @@ -439,6 +500,10 @@ msgid "" ">>> text\n" "'Put several strings within parentheses to have them joined together.'" msgstr "" +">>> text = ('Put several strings within parentheses '\n" +"... 'to have them joined together.')\n" +">>> text\n" +"'Put several strings within parentheses to have them joined together.'" #: ../../tutorial/introduction.rst:235 msgid "" @@ -459,6 +524,17 @@ msgid "" " ^^^^^\n" "SyntaxError: invalid syntax" msgstr "" +">>> prefix = 'Py'\n" +">>> prefix 'thon' # 無法串接變數和字串字面值\n" +" File \"\", line 1\n" +" prefix 'thon'\n" +" ^^^^^^\n" +"SyntaxError: invalid syntax\n" +">>> ('un' * 3) 'ium'\n" +" File \"\", line 1\n" +" ('un' * 3) 'ium'\n" +" ^^^^^\n" +"SyntaxError: invalid syntax" #: ../../tutorial/introduction.rst:249 msgid "" @@ -490,6 +566,11 @@ msgid "" ">>> word[5] # character in position 5\n" "'n'" msgstr "" +">>> word = 'Python'\n" +">>> word[0] # 位置 0 的字元\n" +"'P'\n" +">>> word[5] # 位置 5 的字元\n" +"'n'" #: ../../tutorial/introduction.rst:264 msgid "" @@ -505,6 +586,12 @@ msgid "" ">>> word[-6]\n" "'P'" msgstr "" +">>> word[-1] # 最後一個字元\n" +"'n'\n" +">>> word[-2] # 倒數第二個字元\n" +"'o'\n" +">>> word[-6]\n" +"'P'" #: ../../tutorial/introduction.rst:273 msgid "Note that since -0 is the same as 0, negative indices start from -1." @@ -526,6 +613,10 @@ msgid "" ">>> word[2:5] # characters from position 2 (included) to 5 (excluded)\n" "'tho'" msgstr "" +">>> word[0:2] # 從位置 0 (包含) 到 2 (不包含) 的字元\n" +"'Py'\n" +">>> word[2:5] # 從位置 2 (包含) 到 5 (不包含) 的字元\n" +"'tho'" #: ../../tutorial/introduction.rst:283 msgid "" @@ -544,6 +635,12 @@ msgid "" ">>> word[-2:] # characters from the second-last (included) to the end\n" "'on'" msgstr "" +">>> word[:2] # 從開頭到位置 2 (不包含) 的字元\n" +"'Py'\n" +">>> word[4:] # 從位置 4 (包含) 到結尾的字元\n" +"'on'\n" +">>> word[-2:] # 從倒數第二個 (包含) 到結尾的字元\n" +"'on'" #: ../../tutorial/introduction.rst:293 msgid "" @@ -662,6 +759,14 @@ msgid "" " File \"\", line 1, in \n" "TypeError: 'str' object does not support item assignment" msgstr "" +">>> word[0] = 'J'\n" +"Traceback (most recent call last):\n" +" File \"\", line 1, in \n" +"TypeError: 'str' object does not support item assignment\n" +">>> word[2:] = 'py'\n" +"Traceback (most recent call last):\n" +" File \"\", line 1, in \n" +"TypeError: 'str' object does not support item assignment" #: ../../tutorial/introduction.rst:348 msgid "If you need a different string, you should create a new one::" @@ -783,6 +888,12 @@ msgid "" ">>> squares[-3:] # slicing returns a new list\n" "[9, 16, 25]" msgstr "" +">>> squares[0] # 索引回傳項目\n" +"1\n" +">>> squares[-1]\n" +"25\n" +">>> squares[-3:] # 切片回傳新串列\n" +"[9, 16, 25]" #: ../../tutorial/introduction.rst:407 msgid "Lists also support operations like concatenation::" @@ -813,6 +924,12 @@ msgid "" ">>> cubes\n" "[1, 8, 27, 64, 125]" msgstr "" +">>> cubes = [1, 8, 27, 65, 125] # 這裡有問題\n" +">>> 4 ** 3 # 4 的立方是 64,不是 65!\n" +"64\n" +">>> cubes[3] = 64 # 替換錯誤的值\n" +">>> cubes\n" +"[1, 8, 27, 64, 125]" #: ../../tutorial/introduction.rst:422 msgid "" @@ -829,6 +946,10 @@ msgid "" ">>> cubes\n" "[1, 8, 27, 64, 125, 216, 343]" msgstr "" +">>> cubes.append(216) # 加入 6 的立方\n" +">>> cubes.append(7 ** 3) # 以及 7 的立方\n" +">>> cubes\n" +"[1, 8, 27, 64, 125, 216, 343]" #: ../../tutorial/introduction.rst:430 msgid "" diff --git a/tutorial/modules.po b/tutorial/modules.po index 10ae8543c9..83ea14a296 100644 --- a/tutorial/modules.po +++ b/tutorial/modules.po @@ -861,6 +861,29 @@ msgid "" " karaoke.py\n" " ..." msgstr "" +"sound/ Top-level package\n" +" __init__.py Initialize the sound package\n" +" formats/ Subpackage for file format conversions\n" +" __init__.py\n" +" wavread.py\n" +" wavwrite.py\n" +" aiffread.py\n" +" aiffwrite.py\n" +" auread.py\n" +" auwrite.py\n" +" ...\n" +" effects/ Subpackage for sound effects\n" +" __init__.py\n" +" echo.py\n" +" surround.py\n" +" reverse.py\n" +" ...\n" +" filters/ Subpackage for filters\n" +" __init__.py\n" +" equalizer.py\n" +" vocoder.py\n" +" karaoke.py\n" +" ..." #: ../../tutorial/modules.rst:438 msgid "" @@ -1046,6 +1069,14 @@ msgid "" "def reverse(msg: str): # <-- this name shadows the 'reverse.py' submodule\n" " return msg[::-1] # in the case of a 'from sound.effects import *'" msgstr "" +"__all__ = [\n" +" \"echo\", # 指向 'echo.py' 檔案\n" +" \"surround\", # 指向 'surround.py' 檔案\n" +" \"reverse\", # !!! 現在指向 'reverse' 函式 !!!\n" +"]\n" +"\n" +"def reverse(msg: str): # <-- 在 'from sound.effects import *' 的情況下\n" +" return msg[::-1] # 這個名稱遮蔽了 'reverse.py' 子模組" #: ../../tutorial/modules.rst:534 msgid "" diff --git a/tutorial/stdlib2.po b/tutorial/stdlib2.po index deded95c48..90dd24f60f 100644 --- a/tutorial/stdlib2.po +++ b/tutorial/stdlib2.po @@ -145,6 +145,16 @@ msgid "" "... conv['frac_digits'], x), grouping=True)\n" "'$1,234,567.80'" msgstr "" +">>> import locale\n" +">>> locale.setlocale(locale.LC_ALL, 'English_United States.1252')\n" +"'English_United States.1252'\n" +">>> conv = locale.localeconv() # 取得慣例的對映\n" +">>> x = 1234567.8\n" +">>> locale.format_string(\"%d\", x, grouping=True)\n" +"'1,234,567'\n" +">>> locale.format_string(\"%s%.*f\", (conv['currency_symbol'],\n" +"... conv['frac_digits'], x), grouping=True)\n" +"'$1,234,567.80'" #: ../../tutorial/stdlib2.rst:72 msgid "Templating" @@ -321,6 +331,24 @@ msgid "" "\n" " start += extra_size + comp_size # skip to the next header" msgstr "" +"import struct\n" +"\n" +"with open('myfile.zip', 'rb') as f:\n" +" data = f.read()\n" +"\n" +"start = 0\n" +"for i in range(3): # 顯示前 3 個檔案標頭\n" +" start += 14\n" +" fields = struct.unpack('>> import weakref, gc\n" +">>> class A:\n" +"... def __init__(self, value):\n" +"... self.value = value\n" +"... def __repr__(self):\n" +"... return str(self.value)\n" +"...\n" +">>> a = A(10) # 建立一個參照\n" +">>> d = weakref.WeakValueDictionary()\n" +">>> d['primary'] = a # 不會建立參照\n" +">>> d['primary'] # 如果物件仍然存在則取得它\n" +"10\n" +">>> del a # 移除一個參照\n" +">>> gc.collect() # 立即執行垃圾回收\n" +"0\n" +">>> d['primary'] # 項目被自動移除\n" +"Traceback (most recent call last):\n" +" File \"\", line 1, in \n" +" d['primary'] # 項目被自動移除\n" +" File \"C:/python313/lib/weakref.py\", line 46, in __getitem__\n" +" o = self.data[key]()\n" +"KeyError: 'primary'" #: ../../tutorial/stdlib2.rst:290 msgid "Tools for Working with Lists" @@ -673,6 +723,12 @@ msgid "" ">>> [heappop(data) for i in range(3)] # fetch the three smallest entries\n" "[-5, 0, 1]" msgstr "" +">>> from heapq import heapify, heappop, heappush\n" +">>> data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]\n" +">>> heapify(data) # 將串列重新排列為堆積順序\n" +">>> heappush(data, -5) # 加入新項目\n" +">>> [heappop(data) for i in range(3)] # 取得三個最小的項目\n" +"[-5, 0, 1]" #: ../../tutorial/stdlib2.rst:356 msgid "Decimal Floating-Point Arithmetic"