55#
66# Translators:
77# python-doc bot, 2025
8+ # Freesand Leo <yuqinju@163.com>, 2025
89#
910#, fuzzy
1011msgid ""
1112msgstr ""
1213"Project-Id-Version : Python 3.14\n "
1314"Report-Msgid-Bugs-To : \n "
14- "POT-Creation-Date : 2025-09 -07 14:14 +0000\n "
15+ "POT-Creation-Date : 2025-10 -07 14:17 +0000\n "
1516"PO-Revision-Date : 2025-09-16 00:02+0000\n "
16- "Last-Translator : python-doc bot , 2025\n "
17+ "Last-Translator : Freesand Leo <yuqinju@163.com> , 2025\n "
1718"Language-Team : Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n "
1819"MIME-Version : 1.0\n "
1920"Content-Type : text/plain; charset=UTF-8\n "
@@ -903,13 +904,23 @@ msgid ""
903904"The main operations on a dictionary are storing a value with some key and "
904905"extracting the value given the key. It is also possible to delete a "
905906"key:value pair with ``del``. If you store using a key that is already in "
906- "use, the old value associated with that key is forgotten. It is an error to"
907- " extract a value using a non-existent key."
907+ "use, the old value associated with that key is forgotten."
908908msgstr ""
909- "字典的主要用途是通过关键字存储、提取值。用 ``del`` "
910- "可以删除键值对。用已存在的关键字存储值,与该关键字关联的旧值会被取代。通过不存在的键提取值,则会报错 。"
909+ "字典的主要操作是通过键来存储值并根据给定的键来提取值。 通过 ``del`` 也可以删除键值对。 "
910+ "如果你使用已存在的键进行存储,则与该键相关联的旧值将丢失 。"
911911
912- #: ../../tutorial/datastructures.rst:518
912+ #: ../../tutorial/datastructures.rst:517
913+ msgid ""
914+ "Extracting a value for a non-existent key by subscripting (``d[key]``) "
915+ "raises a :exc:`KeyError`. To avoid getting this error when trying to access "
916+ "a possibly non-existent key, use the :meth:`~dict.get` method instead, which"
917+ " returns ``None`` (or a specified default value) if the key is not in the "
918+ "dictionary."
919+ msgstr ""
920+ "通过下标操作 (``d[key]``) 提取不存在的键的值会引发 :exc:`KeyError`。 要避免在试图访问可能不存在的键时遇到这种错误,可改用"
921+ " :meth:`~dict.get` 方法,它会在字典不存在某个键时返回 ``None`` (或指定的默认值)。"
922+
923+ #: ../../tutorial/datastructures.rst:522
913924msgid ""
914925"Performing ``list(d)`` on a dictionary returns a list of all the keys used "
915926"in the dictionary, in insertion order (if you want it sorted, just use "
@@ -919,18 +930,24 @@ msgstr ""
919930"对字典执行 ``list(d)`` 操作,返回该字典中所有键的列表,按插入次序排列(如需排序,请使用 "
920931"``sorted(d)``)。检查字典里是否存在某个键,使用关键字 :keyword:`in`。"
921932
922- #: ../../tutorial/datastructures.rst:523
933+ #: ../../tutorial/datastructures.rst:527
923934msgid "Here is a small example using a dictionary::"
924935msgstr "以下是一些字典的简单示例:"
925936
926- #: ../../tutorial/datastructures.rst:525
937+ #: ../../tutorial/datastructures.rst:529
927938msgid ""
928939">>> tel = {'jack': 4098, 'sape': 4139}\n"
929940">>> tel['guido'] = 4127\n"
930941">>> tel\n"
931942"{'jack': 4098, 'sape': 4139, 'guido': 4127}\n"
932943">>> tel['jack']\n"
933944"4098\n"
945+ ">>> tel['irv']\n"
946+ "Traceback (most recent call last):\n"
947+ " File \" <stdin>\" , line 1, in <module>\n"
948+ "KeyError: 'irv'\n"
949+ ">>> print(tel.get('irv'))\n"
950+ "None\n"
934951">>> del tel['sape']\n"
935952">>> tel['irv'] = 4127\n"
936953">>> tel\n"
@@ -950,6 +967,12 @@ msgstr ""
950967"{'jack': 4098, 'sape': 4139, 'guido': 4127}\n"
951968">>> tel['jack']\n"
952969"4098\n"
970+ ">>> tel['irv']\n"
971+ "Traceback (most recent call last):\n"
972+ " File \" <stdin>\" , line 1, in <module>\n"
973+ "KeyError: 'irv'\n"
974+ ">>> print(tel.get('irv'))\n"
975+ "None\n"
953976">>> del tel['sape']\n"
954977">>> tel['irv'] = 4127\n"
955978">>> tel\n"
@@ -963,59 +986,59 @@ msgstr ""
963986">>> 'jack' not in tel\n"
964987"False"
965988
966- #: ../../tutorial/datastructures.rst:544
989+ #: ../../tutorial/datastructures.rst:554
967990msgid ""
968991"The :func:`dict` constructor builds dictionaries directly from sequences of "
969992"key-value pairs::"
970993msgstr ":func:`dict` 构造函数可以直接用键值对序列创建字典:"
971994
972- #: ../../tutorial/datastructures.rst:547
995+ #: ../../tutorial/datastructures.rst:557
973996msgid ""
974997">>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])\n"
975998"{'sape': 4139, 'guido': 4127, 'jack': 4098}"
976999msgstr ""
9771000">>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])\n"
9781001"{'sape': 4139, 'guido': 4127, 'jack': 4098}"
9791002
980- #: ../../tutorial/datastructures.rst:550
1003+ #: ../../tutorial/datastructures.rst:560
9811004msgid ""
9821005"In addition, dict comprehensions can be used to create dictionaries from "
9831006"arbitrary key and value expressions::"
9841007msgstr "字典推导式可以用任意键值表达式创建字典:"
9851008
986- #: ../../tutorial/datastructures.rst:553
1009+ #: ../../tutorial/datastructures.rst:563
9871010msgid ""
9881011">>> {x: x**2 for x in (2, 4, 6)}\n"
9891012"{2: 4, 4: 16, 6: 36}"
9901013msgstr ""
9911014">>> {x: x**2 for x in (2, 4, 6)}\n"
9921015"{2: 4, 4: 16, 6: 36}"
9931016
994- #: ../../tutorial/datastructures.rst:556
1017+ #: ../../tutorial/datastructures.rst:566
9951018msgid ""
9961019"When the keys are simple strings, it is sometimes easier to specify pairs "
9971020"using keyword arguments::"
9981021msgstr "关键字是比较简单的字符串时,直接用关键字参数指定键值对更便捷:"
9991022
1000- #: ../../tutorial/datastructures.rst:559
1023+ #: ../../tutorial/datastructures.rst:569
10011024msgid ""
10021025">>> dict(sape=4139, guido=4127, jack=4098)\n"
10031026"{'sape': 4139, 'guido': 4127, 'jack': 4098}"
10041027msgstr ""
10051028">>> dict(sape=4139, guido=4127, jack=4098)\n"
10061029"{'sape': 4139, 'guido': 4127, 'jack': 4098}"
10071030
1008- #: ../../tutorial/datastructures.rst:566
1031+ #: ../../tutorial/datastructures.rst:576
10091032msgid "Looping Techniques"
10101033msgstr "循环的技巧"
10111034
1012- #: ../../tutorial/datastructures.rst:568
1035+ #: ../../tutorial/datastructures.rst:578
10131036msgid ""
10141037"When looping through dictionaries, the key and corresponding value can be "
10151038"retrieved at the same time using the :meth:`~dict.items` method. ::"
10161039msgstr "当对字典执行循环时,可以使用 :meth:`~dict.items` 方法同时提取键及其对应的值。 ::"
10171040
1018- #: ../../tutorial/datastructures.rst:571
1041+ #: ../../tutorial/datastructures.rst:581
10191042msgid ""
10201043">>> knights = {'gallahad': 'the pure', 'robin': 'the brave'}\n"
10211044">>> for k, v in knights.items():\n"
@@ -1031,13 +1054,13 @@ msgstr ""
10311054"gallahad the pure\n"
10321055"robin the brave"
10331056
1034- #: ../../tutorial/datastructures.rst:578
1057+ #: ../../tutorial/datastructures.rst:588
10351058msgid ""
10361059"When looping through a sequence, the position index and corresponding value "
10371060"can be retrieved at the same time using the :func:`enumerate` function. ::"
10381061msgstr "在序列中循环时,用 :func:`enumerate` 函数可以同时取出位置索引和对应的值:"
10391062
1040- #: ../../tutorial/datastructures.rst:581
1063+ #: ../../tutorial/datastructures.rst:591
10411064msgid ""
10421065">>> for i, v in enumerate(['tic', 'tac', 'toe']):\n"
10431066"... print(i, v)\n"
@@ -1053,13 +1076,13 @@ msgstr ""
10531076"1 tac\n"
10541077"2 toe"
10551078
1056- #: ../../tutorial/datastructures.rst:588
1079+ #: ../../tutorial/datastructures.rst:598
10571080msgid ""
10581081"To loop over two or more sequences at the same time, the entries can be "
10591082"paired with the :func:`zip` function. ::"
10601083msgstr "同时循环两个或多个序列时,用 :func:`zip` 函数可以将其内的元素一一匹配:"
10611084
1062- #: ../../tutorial/datastructures.rst:591
1085+ #: ../../tutorial/datastructures.rst:601
10631086msgid ""
10641087">>> questions = ['name', 'quest', 'favorite color']\n"
10651088">>> answers = ['lancelot', 'the holy grail', 'blue']\n"
@@ -1079,13 +1102,13 @@ msgstr ""
10791102"What is your quest? It is the holy grail.\n"
10801103"What is your favorite color? It is blue."
10811104
1082- #: ../../tutorial/datastructures.rst:600
1105+ #: ../../tutorial/datastructures.rst:610
10831106msgid ""
10841107"To loop over a sequence in reverse, first specify the sequence in a forward "
10851108"direction and then call the :func:`reversed` function. ::"
10861109msgstr "为了逆向对序列进行循环,可以求出欲循环的正向序列,然后调用 :func:`reversed` 函数:"
10871110
1088- #: ../../tutorial/datastructures.rst:603
1111+ #: ../../tutorial/datastructures.rst:613
10891112msgid ""
10901113">>> for i in reversed(range(1, 10, 2)):\n"
10911114"... print(i)\n"
@@ -1105,13 +1128,13 @@ msgstr ""
11051128"3\n"
11061129"1"
11071130
1108- #: ../../tutorial/datastructures.rst:612
1131+ #: ../../tutorial/datastructures.rst:622
11091132msgid ""
11101133"To loop over a sequence in sorted order, use the :func:`sorted` function "
11111134"which returns a new sorted list while leaving the source unaltered. ::"
11121135msgstr "按指定顺序循环序列,可以用 :func:`sorted` 函数,在不改动原序列的基础上,返回一个重新的序列:"
11131136
1114- #: ../../tutorial/datastructures.rst:615
1137+ #: ../../tutorial/datastructures.rst:625
11151138msgid ""
11161139">>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']\n"
11171140">>> for i in sorted(basket):\n"
@@ -1135,7 +1158,7 @@ msgstr ""
11351158"orange\n"
11361159"pear"
11371160
1138- #: ../../tutorial/datastructures.rst:626
1161+ #: ../../tutorial/datastructures.rst:636
11391162msgid ""
11401163"Using :func:`set` on a sequence eliminates duplicate elements. The use of "
11411164":func:`sorted` in combination with :func:`set` over a sequence is an "
@@ -1145,7 +1168,7 @@ msgstr ""
11451168"使用 :func:`set` 去除序列中的重复元素。使用 :func:`sorted` 加 :func:`set` "
11461169"则按排序后的顺序,循环遍历序列中的唯一元素:"
11471170
1148- #: ../../tutorial/datastructures.rst:630
1171+ #: ../../tutorial/datastructures.rst:640
11491172msgid ""
11501173">>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']\n"
11511174">>> for f in sorted(set(basket)):\n"
@@ -1165,13 +1188,13 @@ msgstr ""
11651188"orange\n"
11661189"pear"
11671190
1168- #: ../../tutorial/datastructures.rst:639
1191+ #: ../../tutorial/datastructures.rst:649
11691192msgid ""
11701193"It is sometimes tempting to change a list while you are looping over it; "
11711194"however, it is often simpler and safer to create a new list instead. ::"
11721195msgstr "一般来说,在循环中修改列表的内容时,创建新列表比较简单,且安全:"
11731196
1174- #: ../../tutorial/datastructures.rst:642
1197+ #: ../../tutorial/datastructures.rst:652
11751198msgid ""
11761199">>> import math\n"
11771200">>> raw_data = [56.2, float('NaN'), 51.7, 55.3, 52.5, float('NaN'), 47.8]\n"
@@ -1193,17 +1216,17 @@ msgstr ""
11931216">>> filtered_data\n"
11941217"[56.2, 51.7, 55.3, 52.5, 47.8]"
11951218
1196- #: ../../tutorial/datastructures.rst:656
1219+ #: ../../tutorial/datastructures.rst:666
11971220msgid "More on Conditions"
11981221msgstr "深入条件控制"
11991222
1200- #: ../../tutorial/datastructures.rst:658
1223+ #: ../../tutorial/datastructures.rst:668
12011224msgid ""
12021225"The conditions used in ``while`` and ``if`` statements can contain any "
12031226"operators, not just comparisons."
12041227msgstr "``while`` 和 ``if`` 条件句不只可以进行比较,还可以使用任意运算符。"
12051228
1206- #: ../../tutorial/datastructures.rst:662
1229+ #: ../../tutorial/datastructures.rst:672
12071230msgid ""
12081231"The comparison operators ``in`` and ``not in`` are membership tests that "
12091232"determine whether a value is in (or not in) a container. The operators "
@@ -1214,13 +1237,13 @@ msgstr ""
12141237"比较运算符 ``in`` 和 ``not in`` 用于执行确定一个值是否存在(或不存在)于某个容器中的成员检测。 运算符 ``is`` 和 ``is "
12151238"not`` 用于比较两个对象是否是同一个对象。 所有比较运算符的优先级都一样,且低于任何数值运算符。"
12161239
1217- #: ../../tutorial/datastructures.rst:668
1240+ #: ../../tutorial/datastructures.rst:678
12181241msgid ""
12191242"Comparisons can be chained. For example, ``a < b == c`` tests whether ``a``"
12201243" is less than ``b`` and moreover ``b`` equals ``c``."
12211244msgstr "比较操作支持链式操作。例如,``a < b == c`` 校验 ``a`` 是否小于 ``b``,且 ``b`` 是否等于 ``c``。"
12221245
1223- #: ../../tutorial/datastructures.rst:671
1246+ #: ../../tutorial/datastructures.rst:681
12241247msgid ""
12251248"Comparisons may be combined using the Boolean operators ``and`` and ``or``, "
12261249"and the outcome of a comparison (or of any other Boolean expression) may be "
@@ -1233,7 +1256,7 @@ msgstr ""
12331256"取反。这些操作符的优先级低于比较操作符;``not`` 的优先级最高, ``or`` 的优先级最低,因此,``A and not B or C`` "
12341257"等价于 ``(A and (not B)) or C``。与其他运算符操作一样,此处也可以用圆括号表示想要的组合。"
12351258
1236- #: ../../tutorial/datastructures.rst:678
1259+ #: ../../tutorial/datastructures.rst:688
12371260msgid ""
12381261"The Boolean operators ``and`` and ``or`` are so-called *short-circuit* "
12391262"operators: their arguments are evaluated from left to right, and evaluation "
@@ -1246,13 +1269,13 @@ msgstr ""
12461269" ``C`` 为真,``B`` 为假,那么 ``A and B and C`` 不会对 ``C`` "
12471270"求值。用作普通值而不是布尔值时,短路运算符的返回值通常是最后一个求了值的参数。"
12481271
1249- #: ../../tutorial/datastructures.rst:685
1272+ #: ../../tutorial/datastructures.rst:695
12501273msgid ""
12511274"It is possible to assign the result of a comparison or other Boolean "
12521275"expression to a variable. For example, ::"
12531276msgstr "还可以把比较运算或其它布尔表达式的结果赋值给变量,例如:"
12541277
1255- #: ../../tutorial/datastructures.rst:688
1278+ #: ../../tutorial/datastructures.rst:698
12561279msgid ""
12571280">>> string1, string2, string3 = '', 'Trondheim', 'Hammer Dance'\n"
12581281">>> non_null = string1 or string2 or string3\n"
@@ -1264,7 +1287,7 @@ msgstr ""
12641287">>> non_null\n"
12651288"'Trondheim'"
12661289
1267- #: ../../tutorial/datastructures.rst:693
1290+ #: ../../tutorial/datastructures.rst:703
12681291msgid ""
12691292"Note that in Python, unlike C, assignment inside expressions must be done "
12701293"explicitly with the :ref:`walrus operator <why-can-t-i-use-an-assignment-in-"
@@ -1274,11 +1297,11 @@ msgstr ""
12741297"注意,Python 与 C 不同,在表达式内部赋值必须显式使用 :ref:`海象运算符 <why-can-t-i-use-an-assignment-"
12751298"in-an-expression>` ``:=``。 这避免了 C 程序中常见的问题:要在表达式中写 ``==`` 时,却写成了 ``=``。"
12761299
1277- #: ../../tutorial/datastructures.rst:703
1300+ #: ../../tutorial/datastructures.rst:713
12781301msgid "Comparing Sequences and Other Types"
12791302msgstr "序列和其他类型的比较"
12801303
1281- #: ../../tutorial/datastructures.rst:704
1304+ #: ../../tutorial/datastructures.rst:714
12821305msgid ""
12831306"Sequence objects typically may be compared to other objects with the same "
12841307"sequence type. The comparison uses *lexicographical* ordering: first the "
@@ -1297,7 +1320,7 @@ msgstr ""
12971320"顺序:首先,比较前两个对应元素,如果不相等,则可确定比较结果;如果相等,则比较之后的两个元素,以此类推,直到其中一个序列结束。如果要比较的两个元素本身是相同类型的序列,则递归地执行字典式顺序比较。如果两个序列中所有的对应元素都相等,则两个序列相等。如果一个序列是另一个的初始子序列,则较短的序列可被视为较小(较少)的序列。"
12981321" 对于字符串来说,字典式顺序使用 Unicode 码位序号排序单个字符。下面列出了一些比较相同类型序列的例子:"
12991322
1300- #: ../../tutorial/datastructures.rst:716
1323+ #: ../../tutorial/datastructures.rst:726
13011324msgid ""
13021325"(1, 2, 3) < (1, 2, 4)\n"
13031326"[1, 2, 3] < [1, 2, 4]\n"
@@ -1315,7 +1338,7 @@ msgstr ""
13151338"(1, 2, 3) == (1.0, 2.0, 3.0)\n"
13161339"(1, 2, ('aa', 'ab')) < (1, 2, ('abc', 'a'), 4)"
13171340
1318- #: ../../tutorial/datastructures.rst:724
1341+ #: ../../tutorial/datastructures.rst:734
13191342msgid ""
13201343"Note that comparing objects of different types with ``<`` or ``>`` is legal "
13211344"provided that the objects have appropriate comparison methods. For example,"
@@ -1327,11 +1350,11 @@ msgstr ""
13271350"进行比较。例如,混合的数字类型通过数字值进行比较,所以,0 等于 0.0,等等。如果没有提供合适的比较方法,解释器不会随便给出一个比较结果,而是引发 "
13281351":exc:`TypeError` 异常。"
13291352
1330- #: ../../tutorial/datastructures.rst:732
1353+ #: ../../tutorial/datastructures.rst:742
13311354msgid "Footnotes"
13321355msgstr "备注"
13331356
1334- #: ../../tutorial/datastructures.rst:733
1357+ #: ../../tutorial/datastructures.rst:743
13351358msgid ""
13361359"Other languages may return the mutated object, which allows method chaining,"
13371360" such as ``d->insert(\" a\" )->remove(\" b\" )->sort();``."
0 commit comments