Skip to Content
流畅的Python(第2版)
book

流畅的Python(第2版)

by Luciano Ramalho
April 2023
Intermediate to advanced
769 pages
25h 16m
Chinese
Posts & Telecom Press
Content preview from 流畅的Python(第2版)
694
23
除了要明确把
self
作为参数,限制必须通过
self
访问实例属性也备受批评。例如,
可以参考
A. M. Kuchling
发表的著名文章“
Python Warts
”(存档)。
Kuchling
自己并不
讨厌
self
限定符,但是他提到了这一点——可能是为了呼应
comp.lang.python
邮件列
表中的观点。我自己并不介意输入
self
限定符,这样便于把局部变量和属性区分开。
我介意的是在
def
语句中使用
self
如果讨厌
Python
要求显式使用
self
,可以想想
JavaScript
中隐式
this
那变幻莫测的语
义,这样就会感觉好多了。像这样使用
self
有一些合理之处,
Guido
在他的博客
The
History of Python
中写了一篇文章,题为“
Adding Support for User-Defined Classes
”,
明了相关原因。
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python高级编程(第2版)

Python高级编程(第2版)

Posts & Telecom Press, Michał Jaworski, Tarek Ziadé
Kafka权威指南(第2版)

Kafka权威指南(第2版)

Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty
Python贝叶斯分析(第2版)

Python贝叶斯分析(第2版)

Posts & Telecom Press, Osvaldo Martin

Publisher Resources

ISBN: 9787115612366