没想到 Python 中竟然还藏着这些稀奇古怪的东西...
w3cschool
共 3714字,需浏览 8分钟
·
2022-07-05 06:13
作者 | Rocky0429
来源 | Python空间
>>> import __hello__
Hello world!
>>> from __future__ import braces
File "<stdin>", line 1
SyntaxError: not a chance
哈???
Not a chance???
*#¥*+&¥#%&*¥%##*
future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename)
...
else if (strcmp(feature, "braces") == 0) {
PyErr_SetString(PyExc_SyntaxError,
"not a chance");
PyErr_SyntaxLocation(filename, s->lineno);
return 0;
}
大家欣赏一下源码,我敬他是个人才...
0x02 一个由键盘距离引发的离奇事件
某巨擘觉得在键盘上不等于“!=”隔的太远了,用多了会手指疼,于是在他退休的时候,创建了一个库,一旦导入这个库,判断不相等就只能用“<>”:
>>> from __future__ import barry_as_FLUFL
>>> "Python" <> "C++"
True
>>> "Python" != "C++"
File "<stdin>", line 1
"Python" != "C++"
^
SyntaxError: with Barry as BDFL, use '<>' instead of '!='
>>> import antigravity
网址是:https://xkcd.com/353/
0x04 爱是什么?
>>> 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!
>>> love = this
>>> this is love
True
>>> love is True
False
>>> love is False
False
>>> love is not True or False
True
>>> love is love
True
出处:https://github.com/satwikkansal/wtfpython
我准备把这段代码挂起来,时时刻刻复习...
能写出上面代码的我,真的是会抄啊...
当然了,乱七八糟的蛇蛋还有很多,毕竟开源嘛...
这里是w3cschool编程狮,想学习编程的朋友们关注我们,了解更多的编程知识、IT资讯~
评论