沒想到 Python 中竟然還藏著這些稀奇古怪的東西...

作者 | 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;
}大家欣賞一下源碼,我敬他是個(gè)人才...

0x02 一個(gè)由鍵盤距離引發(fā)的離奇事件
某巨擘覺得在鍵盤上不等于“!=”隔的太遠(yuǎn)了,用多了會(huì)手指疼,于是在他退休的時(shí)候,創(chuàng)建了一個(gè)庫(kù),一旦導(dǎo)入這個(gè)庫(kù),判斷不相等就只能用“<>”:
>>> 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網(wǎng)址是: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
我準(zhǔn)備把這段代碼掛起來,時(shí)時(shí)刻刻復(fù)習(xí)...
能寫出上面代碼的我,真的是會(huì)抄啊...
當(dāng)然了,亂七八糟的蛇蛋還有很多,畢竟開源嘛...


這里是w3cschool編程獅,想學(xué)習(xí)編程的朋友們關(guān)注我們,了解更多的編程知識(shí)、IT資訊~

評(píng)論
圖片
表情
