12,694
stars
+0+1+-7
2,024
forks
512
watchers
13
prs
33
issues
0
releases
–
discussions
README
What the fck Python! 🐍
一些有趣且鲜为人知的 Python 特性.
原始版本: | English
翻译版本: | Vietnamese Tiếng Việt | Spanish Español | Korean 한국어 | Russian Русский | German Deutsch | Add translation
其他模式: | Interactive
[![WTFPL 2.0][license-image]][license-url] [![Commit id][commit-image]][commit-url] [![996.icu][996.icu-image]][996.icu-url]
Python, 是一个设计优美的解释型高级语言, 它提供了很多能让程序员感到舒适的功能特性. 但有的时候, Python 的一些输出结果对于初学者来说似乎并不是那么一目了然.
这个有趣的项目意在收集 Python 中那些难以理解和反人类直觉的例子以及鲜为人知的功能特性, 并尝试讨论这些现象背后真正的原理!
虽然下面的有些例子并不一定会让你觉得 WTFs, 但它们依然有可能会告诉你一些你所不知道的 Python 有趣特性. 我觉得这是一种学习编程语言内部原理的好办法, 而且我相信你也会从中获得乐趣!
如果您是一位经验比较丰富的 Python 程序员, 你可以尝试挑战看是否能一次就找到例子的正确答案. 你可能对其中的一些例子已经比较熟悉了, 那这也许能唤起你当年踩这些坑时的甜蜜回忆 :sweat_smile:
PS: 如果你不是第一次读了, 你可以在这里获取变动内容.
那么, 让我们开始吧...
Table of Contents/目录
- Table of Contents/目录
- Structure of the Examples/示例结构
- Usage/用法
- 👀 Examples/示例
- Section: Strain your brain!/大脑运动!
- First things first!/要事优先
- Strings can be tricky sometimes/微妙的字符串
- Be careful with chained operations/小心链式操作
- How not to use is operator/为什么不使用 is 操作符
- Hash brownies/是时候来点蛋糕了!
- Deep down, we're all the same./本质上,我们都一样.
- Disorder within order/有序中潜藏着无序
- Keep trying.../不停的try
- For what?/为什么?
- Evaluation time discrepancy/执行时机差异
- is not ... is not is (not ...) / is not ... 不是 is (not ...)
- A tic-tac-toe where X wins in the first attempt!/一蹴即至!
- Schrödinger's variable/薛定谔的变量
- The chicken-egg problem/先有鸡还是先有蛋
- Subclass relationships/子类关系
- Methods equality and identity/方法的相等性和唯一性
- All-true-ation/返回True的all函数
- The surprising comma/意外的逗号
- Strings and the backslashes/字符串与反斜杠
- not knot!/别纠结!
- Half triple-quoted strings/三个引号
- What's wrong with booleans?/布尔你咋了?
- Class attributes and instance attributes/类属性和实例属性
- yielding None/生成 None
- Yielding from... return!/生成器里的return
- Nan-reflexivity/Nan的自反性
- Mutating the immutable!/强人所难
- The disappearing variable from outer scope/消失的外部变量
- The mysterious key type conversion/神秘的键型转换
- Let's see if you can guess this?/看看你能否猜到这一点?
- Exceeds the limit for integer string conversion/整型转字符串越界
- Section: Slippery Slopes/滑坡谬误
- Modifying a dictionary while iterating over it/迭代字典时的修改
- Stubborn del operator/坚强的 del
- The out of scope variable/外部作用域变量
- Deleting a list item while iterating/迭代列表时删除元素
- Lossy zip of iterators/丢三落四的zip
- Loop variables leaking out!/循环变量泄漏!
- Beware of default mutable arguments!/当心默认的可变参数!
- Catching the Exceptions/捕获异常
- Same operands, different story!/同人不同命!
- Name resolution ignoring class scope/忽略类作用域的名称解析
- Rounding like a banker/像银行家一样舍入
- Needles in a Haystack/大海捞针
- Splitsies/分割函数
- W