-
-
Notifications
You must be signed in to change notification settings - Fork 214
/
Copy pathdesign.po
1568 lines (1396 loc) · 69.9 KB
/
design.po
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (C) 2001-2024, Python Software Foundation
# This file is distributed under the same license as the Python package.
#
# Translators:
# Ching-Lung Chuang, 2015
# SiriusKoan, 2022
# Steven Hsu <[email protected]>, 2023
msgid ""
msgstr ""
"Project-Id-Version: Python 3.13\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-09-24 07:20+0000\n"
"PO-Revision-Date: 2023-08-31 11:34+0800\n"
"Last-Translator: Steven Hsu <[email protected]>\n"
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
"tw)\n"
"Language: zh_TW\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Poedit 3.3.2\n"
"X-Poedit-Bookmarks: -1,-1,-1,-1,-1,93,25,-1,-1,-1\n"
#: ../../faq/design.rst:3
msgid "Design and History FAQ"
msgstr "設計和歷史常見問答集"
#: ../../faq/design.rst:6
msgid "Contents"
msgstr "目錄"
#: ../../faq/design.rst:11
msgid "Why does Python use indentation for grouping of statements?"
msgstr "為什麼 Python 使用縮排將陳述式進行分組?"
#: ../../faq/design.rst:13
msgid ""
"Guido van Rossum believes that using indentation for grouping is extremely "
"elegant and contributes a lot to the clarity of the average Python program. "
"Most people learn to love this feature after a while."
msgstr ""
"Guido van Rossum 相信使用縮排來分組超級優雅,並且對提高一般 Python 程式的清晰"
"度有許多貢獻。許多人在學習一段時間之後就愛上了這個功能。"
#: ../../faq/design.rst:17
msgid ""
"Since there are no begin/end brackets there cannot be a disagreement between "
"grouping perceived by the parser and the human reader. Occasionally C "
"programmers will encounter a fragment of code like this::"
msgstr ""
"因為沒有開始/結束括號,因此剖析器和人類讀者感知到的分組就不存在分歧。偶爾 C "
"語言的程式設計師會遇到這樣的程式碼片段: ::"
#: ../../faq/design.rst:21
msgid ""
"if (x <= y)\n"
" x++;\n"
" y--;\n"
"z++;"
msgstr ""
"if (x <= y)\n"
" x++;\n"
" y--;\n"
"z++;"
#: ../../faq/design.rst:26
msgid ""
"Only the ``x++`` statement is executed if the condition is true, but the "
"indentation leads many to believe otherwise. Even experienced C programmers "
"will sometimes stare at it a long time wondering as to why ``y`` is being "
"decremented even for ``x > y``."
msgstr ""
"如果條件為真,只有 ``x++`` 陳述式會被執行,但縮排會讓很多人對他有不同的理解。"
"即使是資深的 C 語言開發者有時也會盯著他許久,思考為何即便 ``x > y``,但 "
"``y`` 還是減少了。"
#: ../../faq/design.rst:31
msgid ""
"Because there are no begin/end brackets, Python is much less prone to coding-"
"style conflicts. In C there are many different ways to place the braces. "
"After becoming used to reading and writing code using a particular style, it "
"is normal to feel somewhat uneasy when reading (or being required to write) "
"in a different one."
msgstr ""
"因為沒有開頭與結尾的括號,Python 比起其他語言會更不容易遇到程式碼風格的衝突。"
"在 C 語言中,有多種不同的方法來放置花括號。在習慣讀寫特定風格後,去讀(或是必"
"須去寫)另一種風格會覺得不太舒服。"
#: ../../faq/design.rst:38
msgid ""
"Many coding styles place begin/end brackets on a line by themselves. This "
"makes programs considerably longer and wastes valuable screen space, making "
"it harder to get a good overview of a program. Ideally, a function should "
"fit on one screen (say, 20--30 lines). 20 lines of Python can do a lot more "
"work than 20 lines of C. This is not solely due to the lack of begin/end "
"brackets -- the lack of declarations and the high-level data types are also "
"responsible -- but the indentation-based syntax certainly helps."
msgstr ""
"很多程式碼風格會把 begin/end 獨立放在一行。這會讓程式碼很長且浪費珍貴的螢幕空"
"間,要概覽程式時也變得較為困難。理想上來說,一個函式應該要佔一個螢幕(大概 "
"20 至 30 行)。20 行的 Python 程式碼比起 20 行的 C 程式碼可以做更多事。雖然沒"
"有開頭與結尾的括號並非單一原因(沒有變數宣告及高階的資料型別同樣有關),但縮"
"排式的語法確實給了幫助。"
#: ../../faq/design.rst:48
msgid "Why am I getting strange results with simple arithmetic operations?"
msgstr "為什麼我會從簡單的數學運算得到奇怪的結果?"
#: ../../faq/design.rst:50
msgid "See the next question."
msgstr "請見下一個問題。"
#: ../../faq/design.rst:54
msgid "Why are floating-point calculations so inaccurate?"
msgstr "為何浮點數運算如此不精確?"
#: ../../faq/design.rst:56
msgid "Users are often surprised by results like this::"
msgstr "使用者時常對這樣的結果感到驚訝: ::"
#: ../../faq/design.rst:58
msgid ""
">>> 1.2 - 1.0\n"
"0.19999999999999996"
msgstr ""
">>> 1.2 - 1.0\n"
"0.19999999999999996"
#: ../../faq/design.rst:61
msgid ""
"and think it is a bug in Python. It's not. This has little to do with "
"Python, and much more to do with how the underlying platform handles "
"floating-point numbers."
msgstr ""
"然後認為這是 Python 的 bug,但這並不是。這跟 Python 幾乎沒有關係,而是和底層"
"如何處理浮點數有關係。"
#: ../../faq/design.rst:65
msgid ""
"The :class:`float` type in CPython uses a C ``double`` for storage. A :"
"class:`float` object's value is stored in binary floating-point with a fixed "
"precision (typically 53 bits) and Python uses C operations, which in turn "
"rely on the hardware implementation in the processor, to perform floating-"
"point operations. This means that as far as floating-point operations are "
"concerned, Python behaves like many popular languages including C and Java."
msgstr ""
"CPython 的 :class:`float` 型別使用了 C 的 ``double`` 型別來儲存。一個 :class:"
"`float` 物件的值會以固定的精度(通常為 53 位元)存為二進制浮點數,Python 使"
"用 C 來運算浮點數,而他的結果會依處理器中的硬體實作方式來決定。這表示就浮點數"
"運算來說,Python 和 C、Java 等很多受歡迎的語言有一樣的行為。"
#: ../../faq/design.rst:72
msgid ""
"Many numbers that can be written easily in decimal notation cannot be "
"expressed exactly in binary floating point. For example, after::"
msgstr ""
"很多數字可以簡單地寫成十進位表示,但卻無法簡單地以二進制浮點數表示。比方說,"
"在以下程式碼執行後: ::"
#: ../../faq/design.rst:75
msgid ">>> x = 1.2"
msgstr ">>> x = 1.2"
#: ../../faq/design.rst:77
msgid ""
"the value stored for ``x`` is a (very good) approximation to the decimal "
"value ``1.2``, but is not exactly equal to it. On a typical machine, the "
"actual stored value is::"
msgstr ""
"``x`` 裡的值是一個(很接近)1.2 的估計值,但並非精確地等於 1.2。以一般的電腦"
"來說,他實際儲存的值是: ::"
#: ../../faq/design.rst:81
msgid "1.0011001100110011001100110011001100110011001100110011 (binary)"
msgstr "1.0011001100110011001100110011001100110011001100110011 (binary)"
#: ../../faq/design.rst:83
msgid "which is exactly::"
msgstr "而這個值正是: ::"
#: ../../faq/design.rst:85
msgid "1.1999999999999999555910790149937383830547332763671875 (decimal)"
msgstr "1.1999999999999999555910790149937383830547332763671875 (decimal)"
#: ../../faq/design.rst:87
msgid ""
"The typical precision of 53 bits provides Python floats with 15--16 decimal "
"digits of accuracy."
msgstr "53 位元的精度讓 Python 可以有 15 至 16 小數位的準確度。"
#: ../../faq/design.rst:90
msgid ""
"For a fuller explanation, please see the :ref:`floating-point arithmetic "
"<tut-fp-issues>` chapter in the Python tutorial."
msgstr ""
"要更完全的解釋可以查閱在 Python 教學的\\ :ref:`浮點運算 <tut-fp-issues>`\\ 一"
"章。"
#: ../../faq/design.rst:95
msgid "Why are Python strings immutable?"
msgstr "為什麼 Python 字串不可變動?"
#: ../../faq/design.rst:97
msgid "There are several advantages."
msgstr "有許多優點。"
#: ../../faq/design.rst:99
msgid ""
"One is performance: knowing that a string is immutable means we can allocate "
"space for it at creation time, and the storage requirements are fixed and "
"unchanging. This is also one of the reasons for the distinction between "
"tuples and lists."
msgstr ""
"其一是效能:知道字串不可變動後,我們就可以在創造他的時候就分配好空間,而後他"
"的儲存空間需求就是固定不變的。這也是元組 (tuple) 和串列 (list) 相異的其中一個"
"原因。"
#: ../../faq/design.rst:104
msgid ""
"Another advantage is that strings in Python are considered as \"elemental\" "
"as numbers. No amount of activity will change the value 8 to anything else, "
"and in Python, no amount of activity will change the string \"eight\" to "
"anything else."
msgstr ""
"另一個優點是在 Python 中,字串和數字一樣「基本」。沒有任何行為會把 8 這個數值"
"改成其他數值;同理,在 Python 中也沒有任何行為會修改字串「eight」。"
#: ../../faq/design.rst:112
msgid "Why must 'self' be used explicitly in method definitions and calls?"
msgstr "為何「self」在方法 (method) 定義和呼叫時一定要明確使用?"
#: ../../faq/design.rst:114
msgid ""
"The idea was borrowed from Modula-3. It turns out to be very useful, for a "
"variety of reasons."
msgstr "此構想從 Modula-3 而來。因為許多原因,他可以說是非常實用。"
#: ../../faq/design.rst:117
msgid ""
"First, it's more obvious that you are using a method or instance attribute "
"instead of a local variable. Reading ``self.x`` or ``self.meth()`` makes it "
"absolutely clear that an instance variable or method is used even if you "
"don't know the class definition by heart. In C++, you can sort of tell by "
"the lack of a local variable declaration (assuming globals are rare or "
"easily recognizable) -- but in Python, there are no local variable "
"declarations, so you'd have to look up the class definition to be sure. "
"Some C++ and Java coding standards call for instance attributes to have an "
"``m_`` prefix, so this explicitness is still useful in those languages, too."
msgstr ""
"第一,這樣可以更明顯表現出你在用方法 (method) 或是實例 (instance) 的屬性,而"
"非一個區域變數。即使不知道類別 (class) 的定義,當看到 ``self.x`` 或 ``self."
"meth()``,就會很清楚地知道是正在使用實例的變數或是方法。在 C++ 裡,你可以藉由"
"沒有區域變數宣告來判斷這件事 ── 但在 Python 裡沒有區域變數宣告,所以你必須去"
"看類別的定義來確定。有些 C++ 和 Java 的程式碼規格要求要在實例屬性的名稱加上前"
"綴 ``m_``,所以這種明確性在那些語言也是很好用的。"
#: ../../faq/design.rst:127
msgid ""
"Second, it means that no special syntax is necessary if you want to "
"explicitly reference or call the method from a particular class. In C++, if "
"you want to use a method from a base class which is overridden in a derived "
"class, you have to use the ``::`` operator -- in Python you can write "
"``baseclass.methodname(self, <argument list>)``. This is particularly "
"useful for :meth:`~object.__init__` methods, and in general in cases where a "
"derived class method wants to extend the base class method of the same name "
"and thus has to call the base class method somehow."
msgstr ""
"第二,當你想明確地使用或呼叫在某個類別裡的方法的時候,你不需要特殊的語法。在 "
"C++ 裡,如果你想用一個在繼承類別時被覆寫的基底類別方法,必須要用 ``::`` 運算"
"子 -- 但在 Python 裡,你可以直接寫成 ``baseclass.methodname(self, <argument "
"list>)``。這在 :meth:`~object.__init__` 方法很好用,特別是在一個繼承的類別要"
"擴充基底類別的方法而要呼叫他時。"
#: ../../faq/design.rst:136
msgid ""
"Finally, for instance variables it solves a syntactic problem with "
"assignment: since local variables in Python are (by definition!) those "
"variables to which a value is assigned in a function body (and that aren't "
"explicitly declared global), there has to be some way to tell the "
"interpreter that an assignment was meant to assign to an instance variable "
"instead of to a local variable, and it should preferably be syntactic (for "
"efficiency reasons). C++ does this through declarations, but Python doesn't "
"have declarations and it would be a pity having to introduce them just for "
"this purpose. Using the explicit ``self.var`` solves this nicely. "
"Similarly, for using instance variables, having to write ``self.var`` means "
"that references to unqualified names inside a method don't have to search "
"the instance's directories. To put it another way, local variables and "
"instance variables live in two different namespaces, and you need to tell "
"Python which namespace to use."
msgstr ""
"最後,他解決了關於實例變數指派的語法問題:因為區域變數在 Python 是(定義為)"
"在函式內被指派值的變數(且沒有被明確宣告成全域),所以會需要一個方法來告訴直"
"譯器這個指派運算是針對實例變數,而非針對區域變數,這在語法層面處理較好(為了"
"效率)。C++ 用宣告解決了這件事,但 Python 沒有,而為了這個原因而引入變數宣告"
"機制又略嫌浪費。但使用明確的 ``self.var`` 就可以把這個問題圓滿解決。同理,在"
"用實例變數的時候必須寫成 ``self.var`` 即代表對於在方法中不特定的名稱不需要去"
"看實例的內容。換句話說,區域變數和實例變數存在於兩個不同的命名空間 "
"(namespace),而你需要告訴 Python 要使用哪一個。"
#: ../../faq/design.rst:154
msgid "Why can't I use an assignment in an expression?"
msgstr "為何我不能在運算式 (expression) 中使用指派運算?"
#: ../../faq/design.rst:156
msgid "Starting in Python 3.8, you can!"
msgstr "從 Python 3.8 開始,你可以這麼做了!"
#: ../../faq/design.rst:158
msgid ""
"Assignment expressions using the walrus operator ``:=`` assign a variable in "
"an expression::"
msgstr "指派運算式使用海象運算子 ``:=`` 來在運算式中指派變數值: ::"
#: ../../faq/design.rst:161
msgid ""
"while chunk := fp.read(200):\n"
" print(chunk)"
msgstr ""
"while chunk := fp.read(200):\n"
" print(chunk)"
#: ../../faq/design.rst:164
msgid "See :pep:`572` for more information."
msgstr "更多資訊請見 :pep:`572`。"
#: ../../faq/design.rst:169
msgid ""
"Why does Python use methods for some functionality (e.g. list.index()) but "
"functions for other (e.g. len(list))?"
msgstr ""
"為何 Python 對於一些功能實作使用方法(像是 list.index()),另一些使用函式(像"
"是 len(list))?"
#: ../../faq/design.rst:171
msgid "As Guido said:"
msgstr "如 Guido 所說:"
#: ../../faq/design.rst:173
msgid ""
"(a) For some operations, prefix notation just reads better than postfix -- "
"prefix (and infix!) operations have a long tradition in mathematics which "
"likes notations where the visuals help the mathematician thinking about a "
"problem. Compare the easy with which we rewrite a formula like x*(a+b) into "
"x*a + x*b to the clumsiness of doing the same thing using a raw OO notation."
msgstr ""
"(一) 對一些運算來說,前綴寫法看起來會比後綴寫法好 ── 前綴(和中綴!)運算在"
"數學上有更久遠的傳統,這些符號在視覺上幫助數學家們更容易思考問題。想想把 "
"x*(a+b) 這種式子展開成 x*a + x*b 的簡單,再比較一下古老的圈圈符號記法的笨拙就"
"知道了。"
#: ../../faq/design.rst:180
msgid ""
"(b) When I read code that says len(x) I *know* that it is asking for the "
"length of something. This tells me two things: the result is an integer, and "
"the argument is some kind of container. To the contrary, when I read x."
"len(), I have to already know that x is some kind of container implementing "
"an interface or inheriting from a class that has a standard len(). Witness "
"the confusion we occasionally have when a class that is not implementing a "
"mapping has a get() or keys() method, or something that isn't a file has a "
"write() method."
msgstr ""
"(二) 當我看到一段程式碼寫著 len(x),我\\ *知道*\\ 他要找某個東西的長度。這"
"告訴了我兩件事:結果是一個整數、參數是某種容器。相對地,當我看到 x.len(),我"
"必須先知道 x 是某種容器,並實作了一個介面或是繼承了一個有標準 len() 的類別。"
"遇到一個沒有實作對映 (mapping) 的類別卻有 get() 或 keys() 方法,或是不是檔案"
"但卻有 write() 方法時,我們偶爾會覺得困惑。"
#: ../../faq/design.rst:189
msgid "https://mail.python.org/pipermail/python-3000/2006-November/004643.html"
msgstr ""
"https://mail.python.org/pipermail/python-3000/2006-November/004643.html"
#: ../../faq/design.rst:193
msgid "Why is join() a string method instead of a list or tuple method?"
msgstr "為何 join() 是字串方法而非串列 (list) 或元組 (tuple) 方法?"
#: ../../faq/design.rst:195
msgid ""
"Strings became much more like other standard types starting in Python 1.6, "
"when methods were added which give the same functionality that has always "
"been available using the functions of the string module. Most of these new "
"methods have been widely accepted, but the one which appears to make some "
"programmers feel uncomfortable is::"
msgstr ""
"自 Python 1.6 之後,字串變得很像其他標準的型別,也在此時,一些可以和字串模組"
"的函式有相同功能的方法也被加入。大多數的新方法都被廣泛接受,但有一個方法似乎"
"讓一些程式人員不舒服: ::"
#: ../../faq/design.rst:201
msgid "\", \".join(['1', '2', '4', '8', '16'])"
msgstr "\", \".join(['1', '2', '4', '8', '16'])"
#: ../../faq/design.rst:203
msgid "which gives the result::"
msgstr "結果是: ::"
#: ../../faq/design.rst:205
msgid "\"1, 2, 4, 8, 16\""
msgstr "\"1, 2, 4, 8, 16\""
#: ../../faq/design.rst:207
msgid "There are two common arguments against this usage."
msgstr "通常有兩個反對這個用法的論點。"
#: ../../faq/design.rst:209
msgid ""
"The first runs along the lines of: \"It looks really ugly using a method of "
"a string literal (string constant)\", to which the answer is that it might, "
"but a string literal is just a fixed value. If the methods are to be allowed "
"on names bound to strings there is no logical reason to make them "
"unavailable on literals."
msgstr ""
"第一項這麼說:「用字串文本 (string literal) (字串常數)看起來真的很醜」,也"
"許真的如此,但字串文本就只是一個固定值。如果方法可以用在值為字串的變數上,那"
"沒道理字串文本不能被使用。"
#: ../../faq/design.rst:215
msgid ""
"The second objection is typically cast as: \"I am really telling a sequence "
"to join its members together with a string constant\". Sadly, you aren't. "
"For some reason there seems to be much less difficulty with having :meth:"
"`~str.split` as a string method, since in that case it is easy to see that ::"
msgstr ""
"第二個反對意見通常是:「我是在叫一個序列把它的成員用一個字串常數連接起來」。"
"但很遺憾地,你並不是在這樣做。因為某種原因,把 :meth:`~str.split` 當成字串方"
"法比較簡單,因為這樣我們可以輕易地看到: ::"
#: ../../faq/design.rst:220
msgid "\"1, 2, 4, 8, 16\".split(\", \")"
msgstr "\"1, 2, 4, 8, 16\".split(\", \")"
#: ../../faq/design.rst:222
msgid ""
"is an instruction to a string literal to return the substrings delimited by "
"the given separator (or, by default, arbitrary runs of white space)."
msgstr ""
"這是在叫一個字串文本回傳由指定的分隔符號(或是預設為空白)分出的子字串的指"
"令。"
#: ../../faq/design.rst:225
msgid ""
":meth:`~str.join` is a string method because in using it you are telling the "
"separator string to iterate over a sequence of strings and insert itself "
"between adjacent elements. This method can be used with any argument which "
"obeys the rules for sequence objects, including any new classes you might "
"define yourself. Similar methods exist for bytes and bytearray objects."
msgstr ""
":meth:`~str.join` 是一個字串方法,因為在用他的時候,你是告訴分隔字串去走遍整"
"個字串序列,並將自己插入到相鄰的兩項之間。這個方法的參數可以是任何符合序列規"
"則的物件,包括自定義的新類別。在 bytes 和 bytearray 物件也有類似的方法可用。"
#: ../../faq/design.rst:233
msgid "How fast are exceptions?"
msgstr "例外處理有多快?"
#: ../../faq/design.rst:235
msgid ""
"A :keyword:`try`/:keyword:`except` block is extremely efficient if no "
"exceptions are raised. Actually catching an exception is expensive. In "
"versions of Python prior to 2.0 it was common to use this idiom::"
msgstr ""
"如果沒有例外被丟出,一個 :keyword:`try`/:keyword:`except` 區塊是非常有效率"
"的。事實上,抓捕例外要付出昂貴的代價。在 Python 2.0 以前,這樣使用是相當常見"
"的: ::"
#: ../../faq/design.rst:240
msgid ""
"try:\n"
" value = mydict[key]\n"
"except KeyError:\n"
" mydict[key] = getvalue(key)\n"
" value = mydict[key]"
msgstr ""
"try:\n"
" value = mydict[key]\n"
"except KeyError:\n"
" mydict[key] = getvalue(key)\n"
" value = mydict[key]"
#: ../../faq/design.rst:246
msgid ""
"This only made sense when you expected the dict to have the key almost all "
"the time. If that wasn't the case, you coded it like this::"
msgstr ""
"這只有在你預料這個字典大多數時候都有鍵的時候才合理。如果並非如此,你應該寫"
"成: ::"
#: ../../faq/design.rst:249
msgid ""
"if key in mydict:\n"
" value = mydict[key]\n"
"else:\n"
" value = mydict[key] = getvalue(key)"
msgstr ""
"if key in mydict:\n"
" value = mydict[key]\n"
"else:\n"
" value = mydict[key] = getvalue(key)"
#: ../../faq/design.rst:254
msgid ""
"For this specific case, you could also use ``value = dict.setdefault(key, "
"getvalue(key))``, but only if the ``getvalue()`` call is cheap enough "
"because it is evaluated in all cases."
msgstr ""
"單就這個情況來說,你也可以用 ``value = dict.setdefault(key, "
"getvalue(key))``,不過只有在 ``getvalue()`` 代價不大的時候才能用,畢竟他每次"
"都會被執行。"
#: ../../faq/design.rst:260
msgid "Why isn't there a switch or case statement in Python?"
msgstr "為什麼 Python 內沒有 switch 或 case 陳述式?"
#: ../../faq/design.rst:262
msgid ""
"In general, structured switch statements execute one block of code when an "
"expression has a particular value or set of values. Since Python 3.10 one "
"can easily match literal values, or constants within a namespace, with a "
"``match ... case`` statement. An older alternative is a sequence of ``if... "
"elif... elif... else``."
msgstr ""
#: ../../faq/design.rst:268
msgid ""
"For cases where you need to choose from a very large number of "
"possibilities, you can create a dictionary mapping case values to functions "
"to call. For example::"
msgstr "如果可能性很多,你可以用字典去對映要呼叫的函式。舉例來說: ::"
#: ../../faq/design.rst:272
msgid ""
"functions = {'a': function_1,\n"
" 'b': function_2,\n"
" 'c': self.method_1}\n"
"\n"
"func = functions[value]\n"
"func()"
msgstr ""
"if key in mydict:\n"
" value = mydict[key]\n"
"else:\n"
" value = mydict[key] = getvalue(key)"
#: ../../faq/design.rst:279
msgid ""
"For calling methods on objects, you can simplify yet further by using the :"
"func:`getattr` built-in to retrieve methods with a particular name::"
msgstr ""
"對於呼叫物件裡的方法,你可以利用內建用來找尋特定方法的函式 :func:`getattr` 來"
"做進一步的簡化: ::"
#: ../../faq/design.rst:282
msgid ""
"class MyVisitor:\n"
" def visit_a(self):\n"
" ...\n"
"\n"
" def dispatch(self, value):\n"
" method_name = 'visit_' + str(value)\n"
" method = getattr(self, method_name)\n"
" method()"
msgstr ""
"class MyVisitor:\n"
" def visit_a(self):\n"
" ...\n"
"\n"
" def dispatch(self, value):\n"
" method_name = 'visit_' + str(value)\n"
" method = getattr(self, method_name)\n"
" method()"
#: ../../faq/design.rst:291
msgid ""
"It's suggested that you use a prefix for the method names, such as "
"``visit_`` in this example. Without such a prefix, if values are coming "
"from an untrusted source, an attacker would be able to call any method on "
"your object."
msgstr ""
"我們建議在方法名稱加上前綴,以這個例子來說是 像是 ``visit_``。沒有前綴的話,"
"一旦收到從不信任來源的值,攻擊者便可以隨意呼叫在你的專案內的方法。"
#: ../../faq/design.rst:295
msgid ""
"Imitating switch with fallthrough, as with C's switch-case-default, is "
"possible, much harder, and less needed."
msgstr ""
#: ../../faq/design.rst:300
msgid ""
"Can't you emulate threads in the interpreter instead of relying on an OS-"
"specific thread implementation?"
msgstr "為何不能在直譯器上模擬執行緒,而要使用作業系統的特定實作方式?"
#: ../../faq/design.rst:302
msgid ""
"Answer 1: Unfortunately, the interpreter pushes at least one C stack frame "
"for each Python stack frame. Also, extensions can call back into Python at "
"almost random moments. Therefore, a complete threads implementation "
"requires thread support for C."
msgstr ""
"答案一:很不幸地,直譯器對每個 Python 的堆疊框 (stack frame) 會推至少一個 C "
"的堆疊框。同時,擴充套件可以隨時呼叫 Python,因此完整的實作必須要支援 C 的執"
"行緒。"
#: ../../faq/design.rst:307
msgid ""
"Answer 2: Fortunately, there is `Stackless Python <https://github.com/"
"stackless-dev/stackless/wiki>`_, which has a completely redesigned "
"interpreter loop that avoids the C stack."
msgstr ""
"答案二:幸運地,`無堆疊 (Stackless) Python <https://github.com/stackless-dev/"
"stackless/wiki>`_ 完全重新設計了直譯器迴圈,並避免了 C 堆疊。"
#: ../../faq/design.rst:312
msgid "Why can't lambda expressions contain statements?"
msgstr "為何 lambda 運算式不能包含陳述式?"
#: ../../faq/design.rst:314
msgid ""
"Python lambda expressions cannot contain statements because Python's "
"syntactic framework can't handle statements nested inside expressions. "
"However, in Python, this is not a serious problem. Unlike lambda forms in "
"other languages, where they add functionality, Python lambdas are only a "
"shorthand notation if you're too lazy to define a function."
msgstr ""
"Python 的 lambda 運算式不能包含陳述式是因為 Python 的語法框架無法處理包在運算"
"式中的陳述式。然而,在 Python 裡這並不是一個嚴重的問題。不像在其他語言中有獨"
"立功能的 lambda,Python 的 lambda 只是一個在你懶得定義函式時可用的一個簡寫表"
"達法。"
#: ../../faq/design.rst:320
msgid ""
"Functions are already first class objects in Python, and can be declared in "
"a local scope. Therefore the only advantage of using a lambda instead of a "
"locally defined function is that you don't need to invent a name for the "
"function -- but that's just a local variable to which the function object "
"(which is exactly the same type of object that a lambda expression yields) "
"is assigned!"
msgstr ""
"函式已經是 Python 裡的一級物件 (first class objects),而且可以在區域範圍內被"
"宣告。因此唯一用 lambda 而非區域性的函式的優點就是你不需要多想一個函式名稱 — "
"但這樣就會是一個區域變數被指定成函式物件(和 lambda 運算式的結果同類)!"
#: ../../faq/design.rst:328
msgid "Can Python be compiled to machine code, C or some other language?"
msgstr "Python 可以被編譯成機器語言、C 語言或其他種語言嗎?"
#: ../../faq/design.rst:330
msgid ""
"`Cython <https://cython.org/>`_ compiles a modified version of Python with "
"optional annotations into C extensions. `Nuitka <https://nuitka.net/>`_ is "
"an up-and-coming compiler of Python into C++ code, aiming to support the "
"full Python language."
msgstr ""
"`Cython <https://cython.org/>`_ 可以編譯一個調整過有選擇性註解的 Python 版"
"本。`Nuitka <https://nuitka.net/>`_ 是一個有潛力編譯器,可以把 Python 編譯成 "
"C++,他的目標是支援完整的 Python 語言。"
#: ../../faq/design.rst:337
msgid "How does Python manage memory?"
msgstr "Python 如何管理記憶體?"
#: ../../faq/design.rst:339
msgid ""
"The details of Python memory management depend on the implementation. The "
"standard implementation of Python, :term:`CPython`, uses reference counting "
"to detect inaccessible objects, and another mechanism to collect reference "
"cycles, periodically executing a cycle detection algorithm which looks for "
"inaccessible cycles and deletes the objects involved. The :mod:`gc` module "
"provides functions to perform a garbage collection, obtain debugging "
"statistics, and tune the collector's parameters."
msgstr ""
"Python 記憶體管理的細節取決於實作。Python 的標準實作 :term:`CPython` 使用參照"
"計次 (reference counting) 來偵測不再被存取的物件,並用另一個機制來收集參照循"
"環 (reference cycle)、定期執行循環偵測演算法來找不再使用的循環並刪除相關物"
"件。 :mod:`gc` 模組提供了可以執行垃圾收集、抓取除錯統計數據和調整收集器參數的"
"函式。"
#: ../../faq/design.rst:347
msgid ""
"Other implementations (such as `Jython <https://www.jython.org>`_ or `PyPy "
"<https://pypy.org>`_), however, can rely on a different mechanism such as a "
"full-blown garbage collector. This difference can cause some subtle porting "
"problems if your Python code depends on the behavior of the reference "
"counting implementation."
msgstr ""
"然而,在其他實作(像是 `Jython <https://www.jython.org>`_ 或 `PyPy <https://"
"pypy.org>`_)中,會使用像是成熟的垃圾收集器等不同機制。如果你的 Python 程式碼"
"的表現取決於參照計次的實作,這個相異處會導致一些微小的移植問題。"
#: ../../faq/design.rst:353
msgid ""
"In some Python implementations, the following code (which is fine in "
"CPython) will probably run out of file descriptors::"
msgstr ""
"在一些 Python 實作中,下面這段程式碼(在 CPython 可以正常運作)可能會把檔案描"
"述子 (file descriptor) 用盡: ::"
#: ../../faq/design.rst:356
msgid ""
"for file in very_long_list_of_files:\n"
" f = open(file)\n"
" c = f.read(1)"
msgstr ""
"for file in very_long_list_of_files:\n"
" f = open(file)\n"
" c = f.read(1)"
#: ../../faq/design.rst:360
msgid ""
"Indeed, using CPython's reference counting and destructor scheme, each new "
"assignment to ``f`` closes the previous file. With a traditional GC, "
"however, those file objects will only get collected (and closed) at varying "
"and possibly long intervals."
msgstr ""
"實際上,使用 CPython 的參照計次和解構方案 (destructor scheme),每個對 ``f`` "
"的新指派都會關閉前面打開的檔案。然而用傳統的垃圾回收 (GC) 的話,這些檔案物件"
"只會在不固定且有可能很長的時間後被收集(並關閉)。"
#: ../../faq/design.rst:365
msgid ""
"If you want to write code that will work with any Python implementation, you "
"should explicitly close the file or use the :keyword:`with` statement; this "
"will work regardless of memory management scheme::"
msgstr ""
"如果你希望你的程式碼在任何 Python 實作版本中都可以運作,那你應該清楚地關閉檔"
"案或是使用 :keyword:`with` 陳述式,如此一來,不用管記憶體管理的方法,他也會正"
"常運作: ::"
#: ../../faq/design.rst:369
msgid ""
"for file in very_long_list_of_files:\n"
" with open(file) as f:\n"
" c = f.read(1)"
msgstr ""
"for file in very_long_list_of_files:\n"
" with open(file) as f:\n"
" c = f.read(1)"
#: ../../faq/design.rst:375
msgid "Why doesn't CPython use a more traditional garbage collection scheme?"
msgstr "為何 CPython 不使用更多傳統的垃圾回收機制?"
#: ../../faq/design.rst:377
msgid ""
"For one thing, this is not a C standard feature and hence it's not portable. "
"(Yes, we know about the Boehm GC library. It has bits of assembler code for "
"*most* common platforms, not for all of them, and although it is mostly "
"transparent, it isn't completely transparent; patches are required to get "
"Python to work with it.)"
msgstr ""
"第一,這並不是 C 的標準功能,因此他的可攜性低。(對,我們知道 Boehm GC 函式"
"庫。他有可相容於\\ *大多數*\\ 平台的組合語言程式碼,但依然不是全部,而即便它"
"大多數是通透的,也並不完全,要讓它跟 Python 相容還是需要做一些修補。)"
#: ../../faq/design.rst:383
msgid ""
"Traditional GC also becomes a problem when Python is embedded into other "
"applications. While in a standalone Python it's fine to replace the "
"standard ``malloc()`` and ``free()`` with versions provided by the GC "
"library, an application embedding Python may want to have its *own* "
"substitute for ``malloc()`` and ``free()``, and may not want Python's. "
"Right now, CPython works with anything that implements ``malloc()`` and "
"``free()`` properly."
msgstr ""
"傳統的垃圾收集 (GC) 在 Python 被嵌入其他應用程式時也成了一個問題。在獨立的 "
"Python 程式裡當然可以把標準的 ``malloc()`` 和 ``free()`` 換成 GC 函式庫提供的"
"其他版本;但一個嵌著 Python 的應用程式可能想用\\ *自己*\\ 的 malloc() 和 "
"free() 替代品,而不是用 Python 的。以現在來說,CPython 和實作 malloc() 和 "
"free() 的程式相處融洽。"
#: ../../faq/design.rst:392
msgid "Why isn't all memory freed when CPython exits?"
msgstr "當 CPython 結束時,為何所有的記憶體不會被釋放?"
#: ../../faq/design.rst:394
msgid ""
"Objects referenced from the global namespaces of Python modules are not "
"always deallocated when Python exits. This may happen if there are circular "
"references. There are also certain bits of memory that are allocated by the "
"C library that are impossible to free (e.g. a tool like Purify will complain "
"about these). Python is, however, aggressive about cleaning up memory on "
"exit and does try to destroy every single object."
msgstr ""
"當離開 Python 時,從 Python 模組的全域命名空間來的物件並非總是會被釋放。在有"
"循環引用的時候,這可能會發生。有些記憶體是被 C 函式庫取用的,他們不可能被釋放"
"(例如:像是 Purify 之類的工具會抱怨)。然而,Python 在關閉的時候會積極清理記"
"憶體並嘗試刪除每個物件。"
#: ../../faq/design.rst:401
msgid ""
"If you want to force Python to delete certain things on deallocation use "
"the :mod:`atexit` module to run a function that will force those deletions."
msgstr ""
"如果你想要強迫 Python 在釋放記憶體時刪除特定的東西,你可以用 :mod:`atexit` 模"
"組來執行會強制刪除的函式。"
#: ../../faq/design.rst:406
msgid "Why are there separate tuple and list data types?"
msgstr "為何要把元組 (tuple) 和串列 (list) 分成兩個資料型態?"
#: ../../faq/design.rst:408
msgid ""
"Lists and tuples, while similar in many respects, are generally used in "
"fundamentally different ways. Tuples can be thought of as being similar to "
"Pascal ``records`` or C ``structs``; they're small collections of related "
"data which may be of different types which are operated on as a group. For "
"example, a Cartesian coordinate is appropriately represented as a tuple of "
"two or three numbers."
msgstr ""
"串列和元組在很多方面相當相似,但通常用在完全不同的地方。元組可以想成 Pascal "
"的 ``record`` 或是 C 的 ``struct``,是一小群相關聯但可能是不同型別的資料集"
"合,以一組為單位進行操作。舉例來說,一個笛卡兒坐標系可以適當地表示成一個有二"
"或三個值的元組。"
#: ../../faq/design.rst:415
msgid ""
"Lists, on the other hand, are more like arrays in other languages. They "
"tend to hold a varying number of objects all of which have the same type and "
"which are operated on one-by-one. For example, :func:`os.listdir('.') <os."
"listdir>` returns a list of strings representing the files in the current "
"directory. Functions which operate on this output would generally not break "
"if you added another file or two to the directory."
msgstr ""
"另一方面,串列更像是其他語言的陣列 (array)。他可以有不固定個同類別物件,且為"
"逐項操作。舉例來說,:func:`os.listdir('.') <os.listdir>` 回傳當下目錄裡的檔"
"案,以包含字串的串列表示。如果你新增了幾個檔案到這個目錄,一般來說操作結果的"
"函式也會正常運作。"
#: ../../faq/design.rst:423
msgid ""
"Tuples are immutable, meaning that once a tuple has been created, you can't "
"replace any of its elements with a new value. Lists are mutable, meaning "
"that you can always change a list's elements. Only immutable elements can "
"be used as dictionary keys, and hence only tuples and not lists can be used "
"as keys."
msgstr ""
"元組則是不可變的,代表一旦元組被建立,你就不能夠改變裡面的任何一個值。而串列"
"可變,所以你可以改變裡面的元素。只有不可變的元素可以成為字典的鍵,所以只能把"
"元組當成鍵,而串列則不行。"
#: ../../faq/design.rst:430
msgid "How are lists implemented in CPython?"
msgstr "串列 (list) 在 CPython 中是怎麼實作的?"
#: ../../faq/design.rst:432
msgid ""
"CPython's lists are really variable-length arrays, not Lisp-style linked "
"lists. The implementation uses a contiguous array of references to other "
"objects, and keeps a pointer to this array and the array's length in a list "
"head structure."
msgstr ""
"CPython 的串列 (list) 事實上是可變長度的陣列 (array),而不是像 Lisp 語言的鏈"
"接串列 (linked list)。實作上,他是一個連續的物件參照 (reference) 陣列,並把指"
"向此陣列的指標 (pointer) 和陣列長度存在串列的標頭結構內。"
#: ../../faq/design.rst:436
msgid ""
"This makes indexing a list ``a[i]`` an operation whose cost is independent "
"of the size of the list or the value of the index."
msgstr "因此,用索引來找串列特定項 ``a[i]`` 的代價和串列大小或是索引值無關。"
#: ../../faq/design.rst:439
msgid ""
"When items are appended or inserted, the array of references is resized. "
"Some cleverness is applied to improve the performance of appending items "
"repeatedly; when the array must be grown, some extra space is allocated so "
"the next few times don't require an actual resize."
msgstr ""
"當新物件被新增或插入時,陣列會被調整大小。為了改善多次加入物件的效率,我們有"
"用一些巧妙的方法,當陣列必須變大時,會多收集一些額外的空間,接下來幾次新增時"
"就不需要再調整大小了。"
#: ../../faq/design.rst:446
msgid "How are dictionaries implemented in CPython?"
msgstr "字典 (dictionaries) 在 CPython 中是怎麼實作的?"
#: ../../faq/design.rst:448
msgid ""
"CPython's dictionaries are implemented as resizable hash tables. Compared "
"to B-trees, this gives better performance for lookup (the most common "
"operation by far) under most circumstances, and the implementation is "
"simpler."
msgstr ""
"CPython 的字典是用可調整大小的雜湊表 (hash table) 實作的。比起 B 樹 (B-"
"tree),在搜尋(目前為止最常見的操作)方面有更好的表現,實作上也較為簡單。"
#: ../../faq/design.rst:452
msgid ""
"Dictionaries work by computing a hash code for each key stored in the "
"dictionary using the :func:`hash` built-in function. The hash code varies "
"widely depending on the key and a per-process seed; for example, "
"``'Python'`` could hash to ``-539294296`` while ``'python'``, a string that "
"differs by a single bit, could hash to ``1142331976``. The hash code is "
"then used to calculate a location in an internal array where the value will "
"be stored. Assuming that you're storing keys that all have different hash "
"values, this means that dictionaries take constant time -- *O*\\ (1), in Big-"
"O notation -- to retrieve a key."
msgstr ""
"字典利用內建 :func:`hash` 函式,對每個鍵做雜湊計算。雜湊結果依據鍵的值和個別"
"執行緒 (processes) 的種子而有相當大的差距。例如,``'Python'`` 的雜湊是 "
"``-539294296``,而只差一個字的 ``'python'`` 則是 ``1142331976``。雜湊結果接著"
"被用來計算值在內部陣列儲存的位置。假設你存的鍵都有不同的雜湊值,那字典只需要"
"常數時間 — 用大 O 表示法 (Big-O notation) 就是 *O*\\ (1) — 來找任意一個鍵。"
#: ../../faq/design.rst:463
msgid "Why must dictionary keys be immutable?"
msgstr "為何字典的鍵一定是不可變的?"
#: ../../faq/design.rst:465
msgid ""
"The hash table implementation of dictionaries uses a hash value calculated "
"from the key value to find the key. If the key were a mutable object, its "
"value could change, and thus its hash could also change. But since whoever "
"changes the key object can't tell that it was being used as a dictionary "
"key, it can't move the entry around in the dictionary. Then, when you try "
"to look up the same object in the dictionary it won't be found because its "
"hash value is different. If you tried to look up the old value it wouldn't "
"be found either, because the value of the object found in that hash bin "
"would be different."
msgstr ""
"實作字典用的雜湊表是根據鍵的值做計算從而找到鍵的。如果鍵可變的話,他的值就可"
"以改變,則雜湊的結果也會一起變動。但改變鍵的物件的人無從得知他被用來當成字典"
"的鍵,所以無法修改字典的內容。然後,當你嘗試在字典中尋找這個物件時,因為雜湊"
"值不同的緣故,你找不到他。而如果你嘗試用舊的值去尋找,也一樣找不到,因為他的"
"雜湊結果和原先物件不同。"
#: ../../faq/design.rst:474
msgid ""
"If you want a dictionary indexed with a list, simply convert the list to a "
"tuple first; the function ``tuple(L)`` creates a tuple with the same entries "
"as the list ``L``. Tuples are immutable and can therefore be used as "
"dictionary keys."
msgstr ""
"如果你想要用串列作為字典的索引,把他轉換成元組即可。``tuple(L)`` 函式會建立一"
"個和串列 ``L`` 一樣內容的元組。而元組是不可變的,所以可以用來當成字典的鍵。"
#: ../../faq/design.rst:478
msgid "Some unacceptable solutions that have been proposed:"
msgstr "也有人提出一些不能接受的方法:"
#: ../../faq/design.rst:480
msgid ""
"Hash lists by their address (object ID). This doesn't work because if you "
"construct a new list with the same value it won't be found; e.g.::"
msgstr ""
"用串列的記憶體位址(物件 id)來雜湊。這不會成功,因為你如果用同樣的值建立一個"
"新的串列,是找不到的。舉例來說: ::"
#: ../../faq/design.rst:483
msgid ""
"mydict = {[1, 2]: '12'}\n"
"print(mydict[[1, 2]])"
msgstr ""
"mydict = {[1, 2]: '12'}\n"
"print(mydict[[1, 2]])"
#: ../../faq/design.rst:486
msgid ""
"would raise a :exc:`KeyError` exception because the id of the ``[1, 2]`` "
"used in the second line differs from that in the first line. In other "
"words, dictionary keys should be compared using ``==``, not using :keyword:"
"`is`."
msgstr ""
"這將會導致 :exc:`KeyError` 例外,因為 ``[1, 2]`` 的 id 在第一行和第二行是不同"
"的。換句話說,字典的鍵應該要用 ``==`` 來做比較,而不是用 :keyword:`is`。"
#: ../../faq/design.rst:490
msgid ""
"Make a copy when using a list as a key. This doesn't work because the list, "
"being a mutable object, could contain a reference to itself, and then the "
"copying code would run into an infinite loop."
msgstr ""
"複製一個串列作為鍵。這一樣不會成功,因為串列是可變的,他可以包含自己的參照,"
"所以複製會形成一個無窮迴圈。"
#: ../../faq/design.rst:494
msgid ""
"Allow lists as keys but tell the user not to modify them. This would allow "
"a class of hard-to-track bugs in programs when you forgot or modified a list "
"by accident. It also invalidates an important invariant of dictionaries: "
"every value in ``d.keys()`` is usable as a key of the dictionary."
msgstr ""
"允許串列作為鍵,但告訴使用者不要更動他。當你不小心忘記或是更動了這個串列,會"
"產生一種難以追蹤的 bug。他同時也違背了一項字典的重要定則:在 ``d.keys()`` 的"
"每個值都可以當成字典的鍵。"
#: ../../faq/design.rst:499
msgid ""
"Mark lists as read-only once they are used as a dictionary key. The problem "
"is that it's not just the top-level object that could change its value; you "
"could use a tuple containing a list as a key. Entering anything as a key "
"into a dictionary would require marking all objects reachable from there as "
"read-only -- and again, self-referential objects could cause an infinite "
"loop."
msgstr ""
"一旦串列被當成鍵,把他標記成只能讀取。問題是,這不只要避免最上層的物件改變"
"值,就像用元組包含串列來做為鍵。把一個物件當成鍵,需要將從他開始可以接觸到的"
"所有物件都標記成只能讀取 — 所以再一次,自己參照自己的物件會導致無窮迴圈。"