@@ -207,13 +207,13 @@ msgstr ""
207
207
208
208
#: ../../faq/design.rst:112
209
209
msgid "Why must 'self' be used explicitly in method definitions and calls?"
210
- msgstr ""
210
+ msgstr "為何「self」在方法 (method) 定義和呼叫時一定要明確使用? "
211
211
212
212
#: ../../faq/design.rst:114
213
213
msgid ""
214
214
"The idea was borrowed from Modula-3. It turns out to be very useful, for a "
215
215
"variety of reasons."
216
- msgstr "此構想從Modula-3而來。有許多原因可以說是非常實用 。"
216
+ msgstr "此構想從 Modula-3 而來。因為許多原因,他可以說是非常實用 。"
217
217
218
218
#: ../../faq/design.rst:117
219
219
msgid ""
@@ -227,6 +227,12 @@ msgid ""
227
227
"Some C++ and Java coding standards call for instance attributes to have an "
228
228
"``m_`` prefix, so this explicitness is still useful in those languages, too."
229
229
msgstr ""
230
+ "第一,這樣可以更明顯表現出你在用方法 (method) 或是實例 (instance) 的屬性,而"
231
+ "非一個區域變數。即使不知道類別 (class) 的定義,當看到 ``self.x`` 或 ``self."
232
+ "meth()``,就會很清楚地知道是正在使用實例的變數或是方法。在 C++ 裡,你可以藉由"
233
+ "沒有區域變數宣告來判斷這件事 ── 但在 Python 裡沒有區域變數宣告,所以你必須去"
234
+ "看類別的定義來確定。有些 C++ 和 Java 的程式碼規格要求要在實例屬性的名稱加上前"
235
+ "綴 ``m_``,所以這種明確性在那些語言也是很好用的。"
230
236
231
237
#: ../../faq/design.rst:127
232
238
msgid ""
@@ -239,6 +245,11 @@ msgid ""
239
245
"class method wants to extend the base class method of the same name and thus "
240
246
"has to call the base class method somehow."
241
247
msgstr ""
248
+ "第二,當你想明確地使用或呼叫在某個類別裡的方法的時候,你不需要特殊的語法。在 "
249
+ "C++ 裡,如果你想用一個在繼承類別時被覆寫的基底類別方法,必須要用 ``::`` 運算"
250
+ "子 -- 但在 Python 裡,你可以直接寫成 ``baseclass.methodname(self, <argument "
251
+ "list>)``。這在 :meth:`__init__` 方法很好用,特別是在一個繼承的類別要擴充基底"
252
+ "類別的方法而要呼叫他時。"
242
253
243
254
#: ../../faq/design.rst:136
244
255
msgid ""
@@ -257,6 +268,14 @@ msgid ""
257
268
"instance variables live in two different namespaces, and you need to tell "
258
269
"Python which namespace to use."
259
270
msgstr ""
271
+ "最後,他解決了關於實例變數指派的語法問題:因為區域變數在 Python 是(定義為)"
272
+ "在函數內被指派值的變數(且沒有被明確宣告成全域),所以會需要一個方法來告訴直"
273
+ "譯器這個指派運算是針對實例變數,而非針對區域變數,這在語法層面處理較好(為了"
274
+ "效率)。C++ 用宣告解決了這件事,但 Python 沒有,而為了這個原因而引入變數宣告"
275
+ "機制又略嫌浪費。但使用明確的 ``self.var`` 就可以把這個問題圓滿解決。同理,在"
276
+ "用實例變數的時候必須寫成 ``self.var`` 即代表對於在方法中不特定的名稱不需要去"
277
+ "看實例的內容。換句話說,區域變數和實例變數存在於兩個不同的命名空間 "
278
+ "(namespace),而你需要告訴 Python 要使用哪一個。"
260
279
261
280
#: ../../faq/design.rst:154
262
281
msgid "Why can't I use an assignment in an expression?"
0 commit comments