這是Github上的一個(gè)項(xiàng)目龄毡,英文原版已經(jīng)收獲超8000的星標(biāo)产阱。
https://github.com/leisurelicht/wtfpython-cn
What the f*ck Python!
一些有趣且鮮為人知的 Python 特性.
Python, 是一個(gè)設(shè)計(jì)優(yōu)美的解釋型高級語言, 它提供了很多能讓程序員感到舒適的功能特性. 但有的時(shí)候, Python 的一些輸出結(jié)果對于初學(xué)者來說似乎并不是那么一目了然.
這個(gè)有趣的項(xiàng)目意在收集 Python 中那些難以理解和反人類直覺的例子以及鮮為人知的功能特性, 并嘗試討論這些現(xiàn)象背后真正的原理!
雖然下面的有些例子并不一定會讓你覺得 WTFs, 但它們依然有可能會告訴你一些你所不知道的 Python 有趣特性. 我覺得這是一種學(xué)習(xí)編程語言內(nèi)部原理的好辦法, 而且我相信你也會從中獲得樂趣!
如果您是一位經(jīng)驗(yàn)比較豐富的 Python 程序員, 你可以嘗試挑戰(zhàn)看是否能一次就找到例子的正確答案. 你可能對其中的一些例子已經(jīng)比較熟悉了, 那這也許能喚起你當(dāng)年踩這些坑時(shí)的甜蜜回憶
如果你不是第一次讀了, 你可以在這里獲取變動內(nèi)容.
那么, 讓我們開始吧...
Table of Contents/目錄
Table of Contents/目錄
Structure of the Examples/示例結(jié)構(gòu)
Usage/用法
Examples/示例
Section: Strain your brain!/大腦運(yùn)動!
Strings can be tricky sometimes/微妙的字符串 *
Time for some hash brownies!/是時(shí)候來點(diǎn)蛋糕了!
Return return everywhere!/到處返回潮酒!
Deep down, we're all the same./本質(zhì)上,我們都一樣. *
For what?/為什么?
Evaluation time discrepancy/執(zhí)行時(shí)機(jī)差異
is is not what it is!/出人意料的is!
A tic-tac-toe where X wins in the first attempt!/一蹴即至!
The sticky output function/麻煩的輸出
is not ... is not is (not ...)/is not ... 不是 is (not ...)
The surprising comma/意外的逗號
Backslashes at the end of string/字符串末尾的反斜杠
not knot!/別糾結(jié)!
Half triple-quoted strings/三個(gè)引號
Midnight time doesn't exist?/不存在的午夜?
What's wrong with booleans?/布爾你咋了?
Class attributes and instance attributes/類屬性和實(shí)例屬性
yielding None/生成 None
Mutating the immutable!/強(qiáng)人所難
The disappearing variable from outer scope/消失的外部變量
When True is actually False/真亦假
From filled to None in one instruction.../從有到無...
Subclass relationships/子類關(guān)系 *
The mysterious key type conversion/神秘的鍵型轉(zhuǎn)換 *
Let's see if you can guess this?/看看你能否猜到這一點(diǎn)?
Section: Appearances are deceptive!/外表是靠不住的!
Skipping lines?/跳過一行?
Teleportation/空間移動 *
Well, something is fishy.../嗯, 有些可疑...
Section: Watch out for the landmines!/小心地雷!
Modifying a dictionary while iterating over it/迭代字典時(shí)的修改
Stubborn del operator/堅(jiān)強(qiáng)的 del *
Deleting a list item while iterating/迭代列表時(shí)刪除元素
Loop variables leaking out!/循環(huán)變量泄漏!
Beware of default mutable arguments!/當(dāng)心默認(rèn)的可變參數(shù)!
Catching the Exceptions/捕獲異常
Same operands, different story!/同人不同命!
The out of scope variable/外部作用域變量
Be careful with chained operations/小心鏈?zhǔn)讲僮?br> Name resolution ignoring class scope/忽略類作用域的名稱解析
Needle in a Haystack/大海撈針
Section: The Hidden treasures!/隱藏的寶藏!
Okay Python, Can you make me fly?/Python, 可否帶我飛? *
goto, but why?/goto, 但為什么? *
Brace yourself!/做好思想準(zhǔn)備 *
Let's meet Friendly Language Uncle For Life/讓生活更友好 *
Even Python understands that love is complicated/連Python也知道愛是難言的 *
Yes, it exists!/是的, 它存在!
Inpinity/無限 *
Mangling time!修飾時(shí)間! *
Section: Miscellaneous/雜項(xiàng)
+= is faster/更快的 +=
Let's make a giant string!/來做個(gè)巨大的字符串吧!
Explicit typecast of strings/字符串的顯式類型轉(zhuǎn)換
Minor Ones/小知識點(diǎn)
Contributing/貢獻(xiàn)
Acknowledgements/致謝
License/許可
Help/幫助
Want to surprise your geeky pythonist friends?/想給你的極客朋友一個(gè)驚喜?
Need a pdf version?/需要來一份pdf版的?
Follow Commit/追蹤C(jī)ommit