Python——另类的变态


最近在学习Python,基础知识算是学完了,在学Python的面向对象的内容时,我不禁想感叹一下,Python真是一个另类的变态。

说它另类,是因为它完全不按套路出牌,像C++,JAVA之类面向对象的语言中,构造函数的名字是和类的名称一样的,而Python中,在我看的一些资料中并没有提到 构造函数 一词,但Python有一个叫“魔术方法”的东西,指的是一类方法,其中有一个名为__init()__的方法,其功能和构造函数相似,大部分语言实例化对象靠关键字new,但Python的语法是:对象名 = 类名(),Python中,没有 { } 分隔的代码块,而是靠缩进来判断代码归属,Python有太多地方不按套路出牌,所以,我认为Python很另类。

说它变态,是因为它因为另类而变得灵活,而且是非常灵活,各种第三方库,开发效率高得可怕(运行效率另说),网上还有一张表情包,如下:img

这张表情包的由来还有一个小故事,据说是有个人惹到了公司的Python工程师,然后这位工程师用Python写了一个短信轰炸机去轰炸那个人,最终那个人登门向那位Python工程师道歉。可见,Python是多么变态。

最后,附上Python之禅(Python交互界面 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!

声明:楓の街|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - Python——另类的变态


Just For Fun...