一、作者建议
import this
"""
The Zen of Python, by Tim Peters
Beautiful is better than ugly. (美丽总比丑陋好)
Explicit is better than implicit. (显式优于隐式)
Simple is better than complex. (简单胜于复杂)
Complex is better than complicated. (复杂总比隐晦好)
Flat is better than nested. (扁平比嵌套好)
Sparse is better than dense. (稀疏胜于稠密)
Readability counts. (可读性很重要)
Special cases aren't special enough to break the rules. (特殊情况不足以打破规则)
Although practicality beats purity. (尽管实用性胜过纯粹性)
Errors should never pass silently. (错误不应该悄无声息地过去)
Unless explicitly silenced. (除非明确沉默)
In the face of ambiguity, refuse the temptation to guess. (面对歧义,拒绝猜测的诱惑)
There should be one-- and preferably only one --obvious way to do it. (应该有一种——最好是只有一种——显而易见的方法来做这件事)
Although that way may not be obvious at first unless you're Dutch. (虽然这种方式可能并不明显,除非你是荷兰人)
Now is better than never. (现在总比没有好)
Although never is often better than *right* now. (虽然从来没有比现在更好)
If the implementation is hard to explain, it's a bad idea. (如果实现很难解释,这是个坏主意)
If the implementation is easy to explain, it may be a good idea. (如果实现很容易解释,这可能是一个好主意)
Namespaces are one honking great idea -- let's do more of those! (命名空间是一个很棒的主意——让我们做更多的事情)
"""
二、Python 保留字
False、None、True、and、as、assert、async、await、break、class、continue、def、del、elif、else、except、finally、for、from、global、if、import、in、is、lambda、nonlocal、not、or、pass、raise、return、try、while、with、yield
三、 Python 魔法方法
# print(dir("hello"))
[
"__add__",
"__class__",
"__contains__",
"__delattr__",
"__dir__",
"__doc__",
"__eq__",
"__format__",
"__ge__",
"__getattribute__",
"__getitem__",
"__getnewargs__",
"__gt__",
"__hash__",
"__init__",
"__init_subclass__",
"__iter__",
"__le__",
"__len__",
"__lt__",
"__mod__",
"__mul__",
"__ne__",
"__new__",
"__reduce__",
"__reduce_ex__",
"__repr__",
"__rmod__",
"__rmul__",
"__setattr__",
"__sizeof__",
"__str__",
"__subclasshook__"
]
1、__new__() & __init__()
- __new__() 是由 object 基类提供的内置静态方法;
- 在通过类名来创建对象的时候,python 的解释器解释器会首先调用 __new__() 分配空间并获得对象的引用;
- 然后,将引用作为第一个参数传递给 __init__() 方法。