Skip to content

Commit fe637c4

Browse files
author
ducheng
committed
All Others
1 parent db1a0fb commit fe637c4

File tree

1 file changed

+73
-71
lines changed

1 file changed

+73
-71
lines changed

README.md

Lines changed: 73 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
<p align="center"><img src="/images/logo.png" alt=""></p>
22
<h1 align="center">What the f*ck Python! 🐍</h1>
3-
<p align="center">An interesting collection of surprising snippets and lesser-known Python features.</p>
3+
<p align="center">一些有趣且鲜为人知的 Python 特性.</p>
44

55
[![WTFPL 2.0][license-image]][license-url] [![Commit id][commit-image]][commit-url]
66

77

8-
Python, being a beautifully designed high-level and interpreter-based programming language, provides us with many features for the programmer's comfort. But sometimes, the outcomes of a Python snippet may not seem obvious to a regular user at first sight.
8+
Python, 是一个设计优美的解释型高级语言, 它提供了很多能让程序员感到舒适的功能特性. 但有的时候, Python 的一些输出结果对于初学者来说似乎并不是那么一目了然.
99

10-
Here is a fun project to collect such tricky & counter-intuitive examples and lesser-known features in Python, attempting to discuss what exactly is happening under the hood!
10+
这个有趣的项目意在收集 Python 中那些难以理解和反人类直觉的例子以及鲜为人知的功能特性, 并尝试讨论这些现象背后真正的原理!
1111

12-
While some of the examples you see below may not be WTFs in the truest sense, but they'll reveal some of the interesting parts of Python that you might be unaware of. I find it a nice way to learn the internals of a programming language, and I think you'll find them interesting as well!
12+
虽然下面的有些例子并不一定会让你觉得 WTFs, 但它们依然有可能会告诉你一些你所不知道的 Python 有趣特性. 我觉得这是一种学习编程语言内部原理的好办法, 而且我相信你也会从中获得乐趣!
1313

14-
If you're an experienced Python programmer, you can take it as a challenge to get most of them right in first attempt. You may be already familiar with some of these examples, and I might be able to revive sweet old memories of yours being bitten by these gotchas :sweat_smile:
14+
如果您是一位经验比较丰富的 Python 程序员, 你可以尝试挑战看是否能一次就找到例子的正确答案. 你可能对其中的一些例子已经比较熟悉了, 那这也许能唤起你当年踩这些坑时的甜蜜回忆 :sweat_smile:
1515

16-
If you're a returning reader, you can learn about the new modifications [here](https://github.com/satwikkansal/wtfpython/releases/).
16+
如果你不是第一次读了, 你可以在[这里](https://github.com/satwikkansal/wtfpython/releases/)获取变动内容.
1717

18-
So, here we go...
18+
那么, 让我们开始吧...
1919

20-
# Table of Contents
20+
# Table of Contents/目录
2121
<!-- TOC -->
2222

23-
- [Table of Contents](#table-of-contents)
24-
- [Structure of the Examples](#structure-of-the-examples)
25-
- [Usage](#usage)
26-
- [👀 Examples](#👀-examples)
27-
- [Section: Strain your brain!](#section-strain-your-brain)
23+
- [Table of Contents/目录](#table-of-contents目录)
24+
- [Structure of the Examples/示例结构](#structure-of-the-examples示例结构)
25+
- [Usage/用法](#usage用法)
26+
- [👀 Examples/示例](#👀-examples示例)
27+
- [Section: Strain your brain!/大脑运动!](#section-strain-your-brain大脑运动)
2828
- [> Strings can be tricky sometimes/微妙的字符串 *](#-strings-can-be-tricky-sometimes微妙的字符串-)
2929
- [> Time for some hash brownies!/是时候来点蛋糕了!](#-time-for-some-hash-brownies是时候来点蛋糕了)
3030
- [> Return return everywhere!/到处返回!](#-return-return-everywhere到处返回)
@@ -50,11 +50,11 @@ So, here we go...
5050
- [> Subclass relationships/子类关系 *](#-subclass-relationships子类关系-)
5151
- [> The mysterious key type conversion/神秘的键型转换 *](#-the-mysterious-key-type-conversion神秘的键型转换-)
5252
- [> Let's see if you can guess this?/看看你能否猜到这一点?](#-lets-see-if-you-can-guess-this看看你能否猜到这一点)
53-
- [Section: Appearances are deceptive!](#section-appearances-are-deceptive)
53+
- [Section: Appearances are deceptive!/外表是靠不住的!](#section-appearances-are-deceptive外表是靠不住的)
5454
- [> Skipping lines?/跳过一行?](#-skipping-lines跳过一行)
5555
- [> Teleportation/空间移动 *](#-teleportation空间移动-)
5656
- [> Well, something is fishy.../嗯, 有些可疑...](#-well-something-is-fishy嗯有些可疑)
57-
- [Section: Watch out for the landmines!](#section-watch-out-for-the-landmines)
57+
- [Section: Watch out for the landmines!/小心地雷!](#section-watch-out-for-the-landmines小心地雷)
5858
- [> Modifying a dictionary while iterating over it/迭代字典时的修改](#-modifying-a-dictionary-while-iterating-over-it迭代字典时的修改)
5959
- [> Stubborn `del` operator/坚强的 `del` *](#-stubborn-del-operator坚强的-del-)
6060
- [> Deleting a list item while iterating/迭代列表时删除元素](#-deleting-a-list-item-while-iterating迭代列表时删除元素)
@@ -66,7 +66,7 @@ So, here we go...
6666
- [> Be careful with chained operations/小心链式操作](#-be-careful-with-chained-operations小心链式操作)
6767
- [> Name resolution ignoring class scope/忽略类作用域的名称解析](#-name-resolution-ignoring-class-scope忽略类作用域的名称解析)
6868
- [> Needle in a Haystack/大海捞针](#-needle-in-a-haystack大海捞针)
69-
- [Section: The Hidden treasures!](#section-the-hidden-treasures)
69+
- [Section: The Hidden treasures!/隐藏的宝藏!](#section-the-hidden-treasures隐藏的宝藏)
7070
- [> Okay Python, Can you make me fly?/Python, 可否带我飞? *](#-okay-python-can-you-make-me-flypython-可否带我飞-)
7171
- [> `goto`, but why?/`goto`, 但为什么? *](#-goto-but-whygoto-但为什么-)
7272
- [> Brace yourself!/做好思想准备 *](#-brace-yourself做好思想准备-)
@@ -75,85 +75,85 @@ So, here we go...
7575
- [> Yes, it exists!/是的, 它存在!](#-yes-it-exists是的-它存在)
7676
- [> Inpinity/无限 *](#-inpinity无限-)
7777
- [> Mangling time!修饰时间! *](#-mangling-time修饰时间-)
78-
- [Section: Miscellaneous](#section-miscellaneous)
78+
- [Section: Miscellaneous/杂项](#section-miscellaneous杂项)
7979
- [> `+=` is faster/更快的 `+=` ](#--is-faster更快的-)
8080
- [> Let's make a giant string!/来做个巨大的字符串吧!](#-lets-make-a-giant-string来做个巨大的字符串吧)
8181
- [> Explicit typecast of strings/字符串的显式类型转换](#-explicit-typecast-of-strings字符串的显式类型转换)
8282
- [> Minor Ones/小知识点](#-minor-ones小知识点)
83-
- [Contributing](#contributing)
84-
- [Acknowledgements](#acknowledgements)
85-
- [🎓 License](#🎓-license)
86-
- [Help](#help)
87-
- [Want to surprise your geeky pythonist friends?](#want-to-surprise-your-geeky-pythonist-friends)
88-
- [Need a pdf version?](#need-a-pdf-version)
89-
- [Follow Commit](#follow-commit)
83+
- [Contributing/贡献](#contributing贡献)
84+
- [Acknowledgements/致谢](#acknowledgements/致谢)
85+
- [🎓 License/许可](#🎓-license许可)
86+
- [Help/帮助](#help帮助)
87+
- [Want to surprise your geeky pythonist friends?/想给你的极客朋友一个惊喜?](#want-to-surprise-your-geeky-pythonist-friends想给你的极客朋友一个惊喜)
88+
- [Need a pdf version?/需要来一份pdf版的?](#need-a-pdf-version需要来一份pdf版的)
89+
- [Follow Commit/追踪Commit](#follow-commit追踪Commit)
9090

9191
<!-- /TOC -->
9292

93-
# Structure of the Examples
93+
# Structure of the Examples/示例结构
9494

95-
All the examples are structured like below:
95+
所有示例的结构都如下所示:
9696

97-
> ### > Some fancy Title *
98-
> The asterisk at the end of the title indicates the example was not present in the first release and has been recently added.
97+
> ### > 一个精选的标题 *
98+
> 标题末尾的星号表示该示例在第一版中不存在,是最近添加的.
9999
>
100100
> ```py
101-
> # Setting up the code.
102-
> # Preparation for the magic...
101+
> # 准备代码.
102+
> # 释放魔法...
103103
> ```
104104
>
105105
> **Output (Python version):**
106106
> ```py
107-
> >>> triggering_statement
108-
> Probably unexpected output
107+
> >>> 触发语句
108+
> 出乎意料的输出结果
109109
> ```
110-
> (Optional): One line describing the unexpected output.
110+
> (可选): 对意外输出结果的简短描述.
111111
>
112112
>
113-
> #### 💡 Explanation:
113+
> #### 💡 说明:
114114
>
115-
> * Brief explanation of what's happening and why is it happening.
115+
> * 简要说明发生了什么以及为什么会发生.
116116
> ```py
117-
> Setting up examples for clarification (if necessary)
117+
> 如有必要, 举例说明
118118
> ```
119119
> **Output:**
120120
> ```py
121-
> >>> trigger # some example that makes it easy to unveil the magic
122-
> # some justified output
121+
> >>> 触发语句 # 一些让魔法变得容易理解的例子
122+
> # 一些正常的输入
123123
> ```
124124
125-
**Note:** All the examples are tested on Python 3.5.2 interactive interpreter, and they should work for all the Python versions unless explicitly specified in the description.
125+
**注意:** 所有的示例都在 Python 3.5.2 版本的交互解释器上测试过, 如果不特别说明应该适用于所有 Python 版本.
126126
127-
# Usage
127+
# Usage/用法
128128
129-
A nice way to get the most out of these examples, in my opinion, will be just to read the examples chronologically, and for every example:
130-
- Carefully read the initial code for setting up the example. If you're an experienced Python programmer, most of the times you will successfully anticipate what's going to happen next.
131-
- Read the output snippets and,
132-
+ Check if the outputs are the same as you'd expect.
133-
+ Make sure if you know the exact reason behind the output being the way it is.
134-
- If no, take a deep breath, and read the explanation (and if you still don't understand, shout out! and create an issue [here](https://github.com/satwikkansal/wtfPython)).
135-
- If yes, give a gentle pat on your back, and you may skip to the next example.
129+
我个人建议, 最好依次阅读下面的示例, 并对每个示例:
130+
- 仔细阅读设置例子最开始的代码. 如果您是一位经验丰富的 Python 程序员, 那么大多数时候您都能成功预期到后面的结果.
131+
- 阅读输出结果,
132+
+ 确认结果是否如你所料.
133+
+ 确认你是否知道这背后的原理.
134+
- 如果不知道, 深呼吸然后阅读说明 (如果你还是看不明白, 别沉默! 可以在[这](https://github.com/satwikkansal/wtfPython)提个 issue).
135+
- 如果知道, 给自己点奖励, 然后去看下一个例子.
136136
137-
PS: You can also read WTFpython at the command line. There's a pypi package and an npm package (supports colored formatting) for the same.
137+
PS: 你也可以在命令行阅读 WTFpython. 我们有 pypi 包 和 npm 包(支持代码高亮).(译: 这两个都是英文版的)
138138
139-
To install the npm package [`wtfpython`](https://www.npmjs.com/package/wtfpython)
139+
安装 npm [`wtfpython`](https://www.npmjs.com/package/wtfpython)
140140
```sh
141141
$ npm install -g wtfpython
142142
```
143143
144-
Alternatively, to install the pypi package [`wtfpython`](https://pypi.python.org/pypi/wtfpython)
144+
或者, 安装 pypi [`wtfpython`](https://pypi.python.org/pypi/wtfpython)
145145
```sh
146146
$ pip install wtfpython -U
147147
```
148148

149-
Now, just run `wtfpython` at the command line which will open this collection in your selected `$PAGER`.
149+
现在, 在命令行中运行 `wtfpython`, 你就可以开始浏览了.
150150

151151
---
152152

153-
# 👀 Examples
153+
# 👀 Examples/示例
154154

155155

156-
## Section: Strain your brain!
156+
## Section: Strain your brain!/大脑运动!
157157

158158
### > Strings can be tricky sometimes/微妙的字符串 *
159159

@@ -1229,7 +1229,7 @@ a, b = a[b] = {}, 5
12291229

12301230
---
12311231

1232-
## Section: Appearances are deceptive!
1232+
## Section: Appearances are deceptive!/外表是靠不住的!
12331233

12341234
### > Skipping lines?/跳过一行?
12351235

@@ -1338,7 +1338,7 @@ def square(x):
13381338

13391339
---
13401340

1341-
## Section: Watch out for the landmines!
1341+
## Section: Watch out for the landmines!/小心地雷!
13421342

13431343

13441344
### > Modifying a dictionary while iterating over it/迭代字典时的修改
@@ -1893,7 +1893,7 @@ tuple()
18931893
---
18941894

18951895

1896-
## Section: The Hidden treasures!
1896+
## Section: The Hidden treasures!/隐藏的宝藏!
18971897

18981898
This section contains few of the lesser-known interesting things about Python that most beginners like me are unaware of (well, not anymore).
18991899

@@ -2163,7 +2163,7 @@ True
21632163

21642164
---
21652165

2166-
## Section: Miscellaneous
2166+
## Section: Miscellaneous/杂项
21672167

21682168

21692169
### > `+=` is faster/更快的 `+=`
@@ -2369,17 +2369,17 @@ nan
23692369

23702370
---
23712371

2372-
# Contributing
2372+
# Contributing/贡献
23732373

2374-
All patches are Welcome! Please see [CONTRIBUTING.md](/CONTRIBUTING.md) for further details.
2374+
欢迎各种补丁! 详情请看[CONTRIBUTING.md](https://github.com/satwikkansal/wtfpython/blob/master/CONTRIBUTING.md).(译: 这是给原库提贡献的要求模版)
23752375

2376-
For discussions, you can either create a new [issue](https://github.com/satwikkansal/wtfpython/issues/new) or ping on the Gitter [channel](https://gitter.im/wtfpython/Lobby)
2376+
你可以通过新建 [issue](https://github.com/satwikkansal/wtfpython/issues/new) 或者在上 [Gitter](https://gitter.im/wtfpython/Lobby) 与我们进行讨论.
23772377

2378-
# Acknowledgements
2378+
# Acknowledgements/致谢
23792379

2380-
The idea and design for this collection were initially inspired by Denys Dovhan's awesome project [wtfjs](https://github.com/denysdovhan/wtfjs). The overwhelming support by the community gave it the shape it is in right now.
2380+
这个系列最初的想法和设计灵感来自于 Denys Dovhan 的项目 [wtfjs](https://github.com/denysdovhan/wtfjs). 社区的强大支持让它成长为现在的模样.
23812381

2382-
#### Some nice Links!
2382+
#### Some nice Links!/一些不错的资源
23832383
* https://www.youtube.com/watch?v=sH4XF6pKKmk
23842384
* https://www.reddit.com/r/Python/comments/3cu6ej/what_are_some_wtf_things_about_python
23852385
* https://sopython.com/wiki/Common_Gotchas_In_Python
@@ -2388,7 +2388,7 @@ The idea and design for this collection were initially inspired by Denys Dovhan'
23882388
* https://www.python.org/doc/humor/
23892389
* https://www.satwikkansal.xyz/archives/posts/python/My-Python-archives/
23902390

2391-
# 🎓 License
2391+
# 🎓 License/许可
23922392

23932393
[![CC 4.0][license-image]][license-url]
23942394

@@ -2397,22 +2397,24 @@ The idea and design for this collection were initially inspired by Denys Dovhan'
23972397
[license-url]: http://www.wtfpl.net
23982398
[license-image]: https://img.shields.io/badge/License-WTFPL%202.0-lightgrey.svg?style=flat-square
23992399

2400-
## Help
2400+
## Help/帮助
24012401

2402-
If you have any wtfs, ideas or suggestions, please share.
2402+
如果您有任何想法或建议,欢迎分享.
24032403

2404-
## Want to surprise your geeky pythonist friends?
2404+
## Want to surprise your geeky pythonist friends?/想给你的极客朋友一个惊喜?
24052405

2406-
You can recommend wtfpython to your friends on Twitter and Linkedin by using these quick links,
2406+
您可以使用这些快链向 Twitter Linkedin 上的朋友推荐 wtfpython,
24072407

24082408
[Twitter](https://twitter.com/intent/tweet?url=https://github.com/satwikkansal/wtfpython&hastags=python,wtfpython)
24092409
| [Linkedin](https://www.linkedin.com/shareArticle?url=https://github.com/satwikkansal&title=What%20the%20f*ck%20Python!&summary=An%20interesting%20collection%20of%20subtle%20and%20tricky%20Python%20snippets.)
24102410

2411-
## Need a pdf version?
2411+
## Need a pdf version?/需要来一份pdf版的?
24122412

2413-
I've received a few requests for the pdf version of wtfpython. You can add your details [here](https://satwikkansal.xyz/wtfpython-pdf/) to get the pdf as soon as it is finished.
2413+
我收到一些想要pdf版本的需求. 你可以快速在[](https://satwikkansal.xyz/wtfpython-pdf/)获得.
24142414

2415-
## Follow Commit
2415+
## Follow Commit/追踪Commit
2416+
2417+
这是中文版 fork 时所处的原库 Commit, 当原库更新时我会跟随更新.
24162418

24172419
[![Commit id][commit-image]][commit-url]
24182420

0 commit comments

Comments
 (0)