5
5
#
6
6
# Translators:
7
7
# python-doc bot, 2025
8
+ # Freesand Leo <yuqinju@163.com>, 2025
8
9
#
9
10
#, fuzzy
10
11
msgid ""
11
12
msgstr ""
12
13
"Project-Id-Version : Python 3.14\n "
13
14
"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 "
15
16
"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 "
17
18
"Language-Team : Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n "
18
19
"MIME-Version : 1.0\n "
19
20
"Content-Type : text/plain; charset=UTF-8\n "
@@ -903,13 +904,23 @@ msgid ""
903
904
"The main operations on a dictionary are storing a value with some key and "
904
905
"extracting the value given the key. It is also possible to delete a "
905
906
"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."
908
908
msgstr ""
909
- "字典的主要用途是通过关键字存储、提取值。用 ``del`` "
910
- "可以删除键值对。用已存在的关键字存储值,与该关键字关联的旧值会被取代。通过不存在的键提取值,则会报错 。"
909
+ "字典的主要操作是通过键来存储值并根据给定的键来提取值。 通过 ``del`` 也可以删除键值对。 "
910
+ "如果你使用已存在的键进行存储,则与该键相关联的旧值将丢失 。"
911
911
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
913
924
msgid ""
914
925
"Performing ``list(d)`` on a dictionary returns a list of all the keys used "
915
926
"in the dictionary, in insertion order (if you want it sorted, just use "
@@ -919,18 +930,24 @@ msgstr ""
919
930
"对字典执行 ``list(d)`` 操作,返回该字典中所有键的列表,按插入次序排列(如需排序,请使用 "
920
931
"``sorted(d)``)。检查字典里是否存在某个键,使用关键字 :keyword:`in`。"
921
932
922
- #: ../../tutorial/datastructures.rst:523
933
+ #: ../../tutorial/datastructures.rst:527
923
934
msgid "Here is a small example using a dictionary::"
924
935
msgstr "以下是一些字典的简单示例:"
925
936
926
- #: ../../tutorial/datastructures.rst:525
937
+ #: ../../tutorial/datastructures.rst:529
927
938
msgid ""
928
939
">>> tel = {'jack': 4098, 'sape': 4139}\n"
929
940
">>> tel['guido'] = 4127\n"
930
941
">>> tel\n"
931
942
"{'jack': 4098, 'sape': 4139, 'guido': 4127}\n"
932
943
">>> tel['jack']\n"
933
944
"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"
934
951
">>> del tel['sape']\n"
935
952
">>> tel['irv'] = 4127\n"
936
953
">>> tel\n"
@@ -950,6 +967,12 @@ msgstr ""
950
967
"{'jack': 4098, 'sape': 4139, 'guido': 4127}\n"
951
968
">>> tel['jack']\n"
952
969
"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"
953
976
">>> del tel['sape']\n"
954
977
">>> tel['irv'] = 4127\n"
955
978
">>> tel\n"
@@ -963,59 +986,59 @@ msgstr ""
963
986
">>> 'jack' not in tel\n"
964
987
"False"
965
988
966
- #: ../../tutorial/datastructures.rst:544
989
+ #: ../../tutorial/datastructures.rst:554
967
990
msgid ""
968
991
"The :func:`dict` constructor builds dictionaries directly from sequences of "
969
992
"key-value pairs::"
970
993
msgstr ":func:`dict` 构造函数可以直接用键值对序列创建字典:"
971
994
972
- #: ../../tutorial/datastructures.rst:547
995
+ #: ../../tutorial/datastructures.rst:557
973
996
msgid ""
974
997
">>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])\n"
975
998
"{'sape': 4139, 'guido': 4127, 'jack': 4098}"
976
999
msgstr ""
977
1000
">>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])\n"
978
1001
"{'sape': 4139, 'guido': 4127, 'jack': 4098}"
979
1002
980
- #: ../../tutorial/datastructures.rst:550
1003
+ #: ../../tutorial/datastructures.rst:560
981
1004
msgid ""
982
1005
"In addition, dict comprehensions can be used to create dictionaries from "
983
1006
"arbitrary key and value expressions::"
984
1007
msgstr "字典推导式可以用任意键值表达式创建字典:"
985
1008
986
- #: ../../tutorial/datastructures.rst:553
1009
+ #: ../../tutorial/datastructures.rst:563
987
1010
msgid ""
988
1011
">>> {x: x**2 for x in (2, 4, 6)}\n"
989
1012
"{2: 4, 4: 16, 6: 36}"
990
1013
msgstr ""
991
1014
">>> {x: x**2 for x in (2, 4, 6)}\n"
992
1015
"{2: 4, 4: 16, 6: 36}"
993
1016
994
- #: ../../tutorial/datastructures.rst:556
1017
+ #: ../../tutorial/datastructures.rst:566
995
1018
msgid ""
996
1019
"When the keys are simple strings, it is sometimes easier to specify pairs "
997
1020
"using keyword arguments::"
998
1021
msgstr "关键字是比较简单的字符串时,直接用关键字参数指定键值对更便捷:"
999
1022
1000
- #: ../../tutorial/datastructures.rst:559
1023
+ #: ../../tutorial/datastructures.rst:569
1001
1024
msgid ""
1002
1025
">>> dict(sape=4139, guido=4127, jack=4098)\n"
1003
1026
"{'sape': 4139, 'guido': 4127, 'jack': 4098}"
1004
1027
msgstr ""
1005
1028
">>> dict(sape=4139, guido=4127, jack=4098)\n"
1006
1029
"{'sape': 4139, 'guido': 4127, 'jack': 4098}"
1007
1030
1008
- #: ../../tutorial/datastructures.rst:566
1031
+ #: ../../tutorial/datastructures.rst:576
1009
1032
msgid "Looping Techniques"
1010
1033
msgstr "循环的技巧"
1011
1034
1012
- #: ../../tutorial/datastructures.rst:568
1035
+ #: ../../tutorial/datastructures.rst:578
1013
1036
msgid ""
1014
1037
"When looping through dictionaries, the key and corresponding value can be "
1015
1038
"retrieved at the same time using the :meth:`~dict.items` method. ::"
1016
1039
msgstr "当对字典执行循环时,可以使用 :meth:`~dict.items` 方法同时提取键及其对应的值。 ::"
1017
1040
1018
- #: ../../tutorial/datastructures.rst:571
1041
+ #: ../../tutorial/datastructures.rst:581
1019
1042
msgid ""
1020
1043
">>> knights = {'gallahad': 'the pure', 'robin': 'the brave'}\n"
1021
1044
">>> for k, v in knights.items():\n"
@@ -1031,13 +1054,13 @@ msgstr ""
1031
1054
"gallahad the pure\n"
1032
1055
"robin the brave"
1033
1056
1034
- #: ../../tutorial/datastructures.rst:578
1057
+ #: ../../tutorial/datastructures.rst:588
1035
1058
msgid ""
1036
1059
"When looping through a sequence, the position index and corresponding value "
1037
1060
"can be retrieved at the same time using the :func:`enumerate` function. ::"
1038
1061
msgstr "在序列中循环时,用 :func:`enumerate` 函数可以同时取出位置索引和对应的值:"
1039
1062
1040
- #: ../../tutorial/datastructures.rst:581
1063
+ #: ../../tutorial/datastructures.rst:591
1041
1064
msgid ""
1042
1065
">>> for i, v in enumerate(['tic', 'tac', 'toe']):\n"
1043
1066
"... print(i, v)\n"
@@ -1053,13 +1076,13 @@ msgstr ""
1053
1076
"1 tac\n"
1054
1077
"2 toe"
1055
1078
1056
- #: ../../tutorial/datastructures.rst:588
1079
+ #: ../../tutorial/datastructures.rst:598
1057
1080
msgid ""
1058
1081
"To loop over two or more sequences at the same time, the entries can be "
1059
1082
"paired with the :func:`zip` function. ::"
1060
1083
msgstr "同时循环两个或多个序列时,用 :func:`zip` 函数可以将其内的元素一一匹配:"
1061
1084
1062
- #: ../../tutorial/datastructures.rst:591
1085
+ #: ../../tutorial/datastructures.rst:601
1063
1086
msgid ""
1064
1087
">>> questions = ['name', 'quest', 'favorite color']\n"
1065
1088
">>> answers = ['lancelot', 'the holy grail', 'blue']\n"
@@ -1079,13 +1102,13 @@ msgstr ""
1079
1102
"What is your quest? It is the holy grail.\n"
1080
1103
"What is your favorite color? It is blue."
1081
1104
1082
- #: ../../tutorial/datastructures.rst:600
1105
+ #: ../../tutorial/datastructures.rst:610
1083
1106
msgid ""
1084
1107
"To loop over a sequence in reverse, first specify the sequence in a forward "
1085
1108
"direction and then call the :func:`reversed` function. ::"
1086
1109
msgstr "为了逆向对序列进行循环,可以求出欲循环的正向序列,然后调用 :func:`reversed` 函数:"
1087
1110
1088
- #: ../../tutorial/datastructures.rst:603
1111
+ #: ../../tutorial/datastructures.rst:613
1089
1112
msgid ""
1090
1113
">>> for i in reversed(range(1, 10, 2)):\n"
1091
1114
"... print(i)\n"
@@ -1105,13 +1128,13 @@ msgstr ""
1105
1128
"3\n"
1106
1129
"1"
1107
1130
1108
- #: ../../tutorial/datastructures.rst:612
1131
+ #: ../../tutorial/datastructures.rst:622
1109
1132
msgid ""
1110
1133
"To loop over a sequence in sorted order, use the :func:`sorted` function "
1111
1134
"which returns a new sorted list while leaving the source unaltered. ::"
1112
1135
msgstr "按指定顺序循环序列,可以用 :func:`sorted` 函数,在不改动原序列的基础上,返回一个重新的序列:"
1113
1136
1114
- #: ../../tutorial/datastructures.rst:615
1137
+ #: ../../tutorial/datastructures.rst:625
1115
1138
msgid ""
1116
1139
">>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']\n"
1117
1140
">>> for i in sorted(basket):\n"
@@ -1135,7 +1158,7 @@ msgstr ""
1135
1158
"orange\n"
1136
1159
"pear"
1137
1160
1138
- #: ../../tutorial/datastructures.rst:626
1161
+ #: ../../tutorial/datastructures.rst:636
1139
1162
msgid ""
1140
1163
"Using :func:`set` on a sequence eliminates duplicate elements. The use of "
1141
1164
":func:`sorted` in combination with :func:`set` over a sequence is an "
@@ -1145,7 +1168,7 @@ msgstr ""
1145
1168
"使用 :func:`set` 去除序列中的重复元素。使用 :func:`sorted` 加 :func:`set` "
1146
1169
"则按排序后的顺序,循环遍历序列中的唯一元素:"
1147
1170
1148
- #: ../../tutorial/datastructures.rst:630
1171
+ #: ../../tutorial/datastructures.rst:640
1149
1172
msgid ""
1150
1173
">>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']\n"
1151
1174
">>> for f in sorted(set(basket)):\n"
@@ -1165,13 +1188,13 @@ msgstr ""
1165
1188
"orange\n"
1166
1189
"pear"
1167
1190
1168
- #: ../../tutorial/datastructures.rst:639
1191
+ #: ../../tutorial/datastructures.rst:649
1169
1192
msgid ""
1170
1193
"It is sometimes tempting to change a list while you are looping over it; "
1171
1194
"however, it is often simpler and safer to create a new list instead. ::"
1172
1195
msgstr "一般来说,在循环中修改列表的内容时,创建新列表比较简单,且安全:"
1173
1196
1174
- #: ../../tutorial/datastructures.rst:642
1197
+ #: ../../tutorial/datastructures.rst:652
1175
1198
msgid ""
1176
1199
">>> import math\n"
1177
1200
">>> raw_data = [56.2, float('NaN'), 51.7, 55.3, 52.5, float('NaN'), 47.8]\n"
@@ -1193,17 +1216,17 @@ msgstr ""
1193
1216
">>> filtered_data\n"
1194
1217
"[56.2, 51.7, 55.3, 52.5, 47.8]"
1195
1218
1196
- #: ../../tutorial/datastructures.rst:656
1219
+ #: ../../tutorial/datastructures.rst:666
1197
1220
msgid "More on Conditions"
1198
1221
msgstr "深入条件控制"
1199
1222
1200
- #: ../../tutorial/datastructures.rst:658
1223
+ #: ../../tutorial/datastructures.rst:668
1201
1224
msgid ""
1202
1225
"The conditions used in ``while`` and ``if`` statements can contain any "
1203
1226
"operators, not just comparisons."
1204
1227
msgstr "``while`` 和 ``if`` 条件句不只可以进行比较,还可以使用任意运算符。"
1205
1228
1206
- #: ../../tutorial/datastructures.rst:662
1229
+ #: ../../tutorial/datastructures.rst:672
1207
1230
msgid ""
1208
1231
"The comparison operators ``in`` and ``not in`` are membership tests that "
1209
1232
"determine whether a value is in (or not in) a container. The operators "
@@ -1214,13 +1237,13 @@ msgstr ""
1214
1237
"比较运算符 ``in`` 和 ``not in`` 用于执行确定一个值是否存在(或不存在)于某个容器中的成员检测。 运算符 ``is`` 和 ``is "
1215
1238
"not`` 用于比较两个对象是否是同一个对象。 所有比较运算符的优先级都一样,且低于任何数值运算符。"
1216
1239
1217
- #: ../../tutorial/datastructures.rst:668
1240
+ #: ../../tutorial/datastructures.rst:678
1218
1241
msgid ""
1219
1242
"Comparisons can be chained. For example, ``a < b == c`` tests whether ``a``"
1220
1243
" is less than ``b`` and moreover ``b`` equals ``c``."
1221
1244
msgstr "比较操作支持链式操作。例如,``a < b == c`` 校验 ``a`` 是否小于 ``b``,且 ``b`` 是否等于 ``c``。"
1222
1245
1223
- #: ../../tutorial/datastructures.rst:671
1246
+ #: ../../tutorial/datastructures.rst:681
1224
1247
msgid ""
1225
1248
"Comparisons may be combined using the Boolean operators ``and`` and ``or``, "
1226
1249
"and the outcome of a comparison (or of any other Boolean expression) may be "
@@ -1233,7 +1256,7 @@ msgstr ""
1233
1256
"取反。这些操作符的优先级低于比较操作符;``not`` 的优先级最高, ``or`` 的优先级最低,因此,``A and not B or C`` "
1234
1257
"等价于 ``(A and (not B)) or C``。与其他运算符操作一样,此处也可以用圆括号表示想要的组合。"
1235
1258
1236
- #: ../../tutorial/datastructures.rst:678
1259
+ #: ../../tutorial/datastructures.rst:688
1237
1260
msgid ""
1238
1261
"The Boolean operators ``and`` and ``or`` are so-called *short-circuit* "
1239
1262
"operators: their arguments are evaluated from left to right, and evaluation "
@@ -1246,13 +1269,13 @@ msgstr ""
1246
1269
" ``C`` 为真,``B`` 为假,那么 ``A and B and C`` 不会对 ``C`` "
1247
1270
"求值。用作普通值而不是布尔值时,短路运算符的返回值通常是最后一个求了值的参数。"
1248
1271
1249
- #: ../../tutorial/datastructures.rst:685
1272
+ #: ../../tutorial/datastructures.rst:695
1250
1273
msgid ""
1251
1274
"It is possible to assign the result of a comparison or other Boolean "
1252
1275
"expression to a variable. For example, ::"
1253
1276
msgstr "还可以把比较运算或其它布尔表达式的结果赋值给变量,例如:"
1254
1277
1255
- #: ../../tutorial/datastructures.rst:688
1278
+ #: ../../tutorial/datastructures.rst:698
1256
1279
msgid ""
1257
1280
">>> string1, string2, string3 = '', 'Trondheim', 'Hammer Dance'\n"
1258
1281
">>> non_null = string1 or string2 or string3\n"
@@ -1264,7 +1287,7 @@ msgstr ""
1264
1287
">>> non_null\n"
1265
1288
"'Trondheim'"
1266
1289
1267
- #: ../../tutorial/datastructures.rst:693
1290
+ #: ../../tutorial/datastructures.rst:703
1268
1291
msgid ""
1269
1292
"Note that in Python, unlike C, assignment inside expressions must be done "
1270
1293
"explicitly with the :ref:`walrus operator <why-can-t-i-use-an-assignment-in-"
@@ -1274,11 +1297,11 @@ msgstr ""
1274
1297
"注意,Python 与 C 不同,在表达式内部赋值必须显式使用 :ref:`海象运算符 <why-can-t-i-use-an-assignment-"
1275
1298
"in-an-expression>` ``:=``。 这避免了 C 程序中常见的问题:要在表达式中写 ``==`` 时,却写成了 ``=``。"
1276
1299
1277
- #: ../../tutorial/datastructures.rst:703
1300
+ #: ../../tutorial/datastructures.rst:713
1278
1301
msgid "Comparing Sequences and Other Types"
1279
1302
msgstr "序列和其他类型的比较"
1280
1303
1281
- #: ../../tutorial/datastructures.rst:704
1304
+ #: ../../tutorial/datastructures.rst:714
1282
1305
msgid ""
1283
1306
"Sequence objects typically may be compared to other objects with the same "
1284
1307
"sequence type. The comparison uses *lexicographical* ordering: first the "
@@ -1297,7 +1320,7 @@ msgstr ""
1297
1320
"顺序:首先,比较前两个对应元素,如果不相等,则可确定比较结果;如果相等,则比较之后的两个元素,以此类推,直到其中一个序列结束。如果要比较的两个元素本身是相同类型的序列,则递归地执行字典式顺序比较。如果两个序列中所有的对应元素都相等,则两个序列相等。如果一个序列是另一个的初始子序列,则较短的序列可被视为较小(较少)的序列。"
1298
1321
" 对于字符串来说,字典式顺序使用 Unicode 码位序号排序单个字符。下面列出了一些比较相同类型序列的例子:"
1299
1322
1300
- #: ../../tutorial/datastructures.rst:716
1323
+ #: ../../tutorial/datastructures.rst:726
1301
1324
msgid ""
1302
1325
"(1, 2, 3) < (1, 2, 4)\n"
1303
1326
"[1, 2, 3] < [1, 2, 4]\n"
@@ -1315,7 +1338,7 @@ msgstr ""
1315
1338
"(1, 2, 3) == (1.0, 2.0, 3.0)\n"
1316
1339
"(1, 2, ('aa', 'ab')) < (1, 2, ('abc', 'a'), 4)"
1317
1340
1318
- #: ../../tutorial/datastructures.rst:724
1341
+ #: ../../tutorial/datastructures.rst:734
1319
1342
msgid ""
1320
1343
"Note that comparing objects of different types with ``<`` or ``>`` is legal "
1321
1344
"provided that the objects have appropriate comparison methods. For example,"
@@ -1327,11 +1350,11 @@ msgstr ""
1327
1350
"进行比较。例如,混合的数字类型通过数字值进行比较,所以,0 等于 0.0,等等。如果没有提供合适的比较方法,解释器不会随便给出一个比较结果,而是引发 "
1328
1351
":exc:`TypeError` 异常。"
1329
1352
1330
- #: ../../tutorial/datastructures.rst:732
1353
+ #: ../../tutorial/datastructures.rst:742
1331
1354
msgid "Footnotes"
1332
1355
msgstr "备注"
1333
1356
1334
- #: ../../tutorial/datastructures.rst:733
1357
+ #: ../../tutorial/datastructures.rst:743
1335
1358
msgid ""
1336
1359
"Other languages may return the mutated object, which allows method chaining,"
1337
1360
" such as ``d->insert(\" a\" )->remove(\" b\" )->sort();``."
0 commit comments