Skip to content

Commit eca709b

Browse files
duchengleisurelicht
ducheng
authored andcommitted
All Others
1 parent 6d689a7 commit eca709b

File tree

1 file changed

+79
-72
lines changed

1 file changed

+79
-72
lines changed

README.md

+79-72
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
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>
4+
5+
<p align="center">
6+
<a href="https://github.com/satwikkansal/wtfpython">English</a>
7+
| <a href="#">中文</a>
8+
</p>
49

510
[![WTFPL 2.0][license-image]][license-url] [![Commit id][commit-image]][commit-url]
611

712

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.
13+
Python, 是一个设计优美的解释型高级语言, 它提供了很多能让程序员感到舒适的功能特性. 但有的时候, Python 的一些输出结果对于初学者来说似乎并不是那么一目了然.
914

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!
15+
这个有趣的项目意在收集 Python 中那些难以理解和反人类直觉的例子以及鲜为人知的功能特性, 并尝试讨论这些现象背后真正的原理!
1116

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!
17+
虽然下面的有些例子并不一定会让你觉得 WTFs, 但它们依然有可能会告诉你一些你所不知道的 Python 有趣特性. 我觉得这是一种学习编程语言内部原理的好办法, 而且我相信你也会从中获得乐趣!
1318

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:
19+
如果您是一位经验比较丰富的 Python 程序员, 你可以尝试挑战看是否能一次就找到例子的正确答案. 你可能对其中的一些例子已经比较熟悉了, 那这也许能唤起你当年踩这些坑时的甜蜜回忆 :sweat_smile:
1520

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

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

20-
# Table of Contents
25+
# Table of Contents/目录
2126
<!-- TOC -->
2227

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)
28+
- [Table of Contents/目录](#table-of-contents目录)
29+
- [Structure of the Examples/示例结构](#structure-of-the-examples示例结构)
30+
- [Usage/用法](#usage用法)
31+
- [👀 Examples/示例](#-examples示例)
32+
- [Section: Strain your brain!/大脑运动!](#section-strain-your-brain大脑运动)
2833
- [> Strings can be tricky sometimes/微妙的字符串 *](#-strings-can-be-tricky-sometimes微妙的字符串-)
2934
- [> Time for some hash brownies!/是时候来点蛋糕了!](#-time-for-some-hash-brownies是时候来点蛋糕了)
3035
- [> Return return everywhere!/到处返回!](#-return-return-everywhere到处返回)
@@ -50,11 +55,11 @@ So, here we go...
5055
- [> Subclass relationships/子类关系 *](#-subclass-relationships子类关系-)
5156
- [> The mysterious key type conversion/神秘的键型转换 *](#-the-mysterious-key-type-conversion神秘的键型转换-)
5257
- [> Let's see if you can guess this?/看看你能否猜到这一点?](#-lets-see-if-you-can-guess-this看看你能否猜到这一点)
53-
- [Section: Appearances are deceptive!](#section-appearances-are-deceptive)
58+
- [Section: Appearances are deceptive!/外表是靠不住的!](#section-appearances-are-deceptive外表是靠不住的)
5459
- [> Skipping lines?/跳过一行?](#-skipping-lines跳过一行)
5560
- [> Teleportation/空间移动 *](#-teleportation空间移动-)
5661
- [> Well, something is fishy.../嗯, 有些可疑...](#-well-something-is-fishy嗯有些可疑)
57-
- [Section: Watch out for the landmines!](#section-watch-out-for-the-landmines)
62+
- [Section: Watch out for the landmines!/小心地雷!](#section-watch-out-for-the-landmines小心地雷)
5863
- [> Modifying a dictionary while iterating over it/迭代字典时的修改](#-modifying-a-dictionary-while-iterating-over-it迭代字典时的修改)
5964
- [> Stubborn `del` operator/坚强的 `del` *](#-stubborn-del-operator坚强的-del-)
6065
- [> Deleting a list item while iterating/迭代列表时删除元素](#-deleting-a-list-item-while-iterating迭代列表时删除元素)
@@ -66,7 +71,7 @@ So, here we go...
6671
- [> Be careful with chained operations/小心链式操作](#-be-careful-with-chained-operations小心链式操作)
6772
- [> Name resolution ignoring class scope/忽略类作用域的名称解析](#-name-resolution-ignoring-class-scope忽略类作用域的名称解析)
6873
- [> Needle in a Haystack/大海捞针](#-needle-in-a-haystack大海捞针)
69-
- [Section: The Hidden treasures!](#section-the-hidden-treasures)
74+
- [Section: The Hidden treasures!/隐藏的宝藏!](#section-the-hidden-treasures隐藏的宝藏)
7075
- [> Okay Python, Can you make me fly?/Python, 可否带我飞? *](#-okay-python-can-you-make-me-flypython-可否带我飞-)
7176
- [> `goto`, but why?/`goto`, 但为什么? *](#-goto-but-whygoto-但为什么-)
7277
- [> Brace yourself!/做好思想准备 *](#-brace-yourself做好思想准备-)
@@ -75,85 +80,85 @@ So, here we go...
7580
- [> Yes, it exists!/是的, 它存在!](#-yes-it-exists是的-它存在)
7681
- [> Inpinity/无限 *](#-inpinity无限-)
7782
- [> Mangling time!修饰时间! *](#-mangling-time修饰时间-)
78-
- [Section: Miscellaneous](#section-miscellaneous)
83+
- [Section: Miscellaneous/杂项](#section-miscellaneous杂项)
7984
- [> `+=` is faster/更快的 `+=` ](#--is-faster更快的-)
8085
- [> Let's make a giant string!/来做个巨大的字符串吧!](#-lets-make-a-giant-string来做个巨大的字符串吧)
8186
- [> Explicit typecast of strings/字符串的显式类型转换](#-explicit-typecast-of-strings字符串的显式类型转换)
8287
- [> 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)
88+
- [Contributing/贡献](#contributing贡献)
89+
- [Acknowledgements/致谢](#acknowledgements致谢)
90+
- [🎓 License/许可](#-license许可)
91+
- [Help/帮助](#help帮助)
92+
- [Surprise your geeky pythonist friends?/想给你的极客朋友一个惊喜?](#surprise-your-geeky-pythonist-friends想给你的极客朋友一个惊喜)
93+
- [Need a pdf version?/需要来一份pdf版的?](#need-a-pdf-version需要来一份pdf版的)
94+
- [Follow Commit/追踪Commit](#follow-commit追踪Commit)
9095

9196
<!-- /TOC -->
9297

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

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

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.
102+
> ### > 一个精选的标题 *
103+
> 标题末尾的星号表示该示例在第一版中不存在,是最近添加的.
99104
>
100105
> ```py
101-
> # Setting up the code.
102-
> # Preparation for the magic...
106+
> # 准备代码.
107+
> # 释放魔法...
103108
> ```
104109
>
105110
> **Output (Python version):**
106111
> ```py
107-
> >>> triggering_statement
108-
> Probably unexpected output
112+
> >>> 触发语句
113+
> 出乎意料的输出结果
109114
> ```
110-
> (Optional): One line describing the unexpected output.
115+
> (可选): 对意外输出结果的简短描述.
111116
>
112117
>
113-
> #### 💡 Explanation:
118+
> #### 💡 说明:
114119
>
115-
> * Brief explanation of what's happening and why is it happening.
120+
> * 简要说明发生了什么以及为什么会发生.
116121
> ```py
117-
> Setting up examples for clarification (if necessary)
122+
> 如有必要, 举例说明
118123
> ```
119124
> **Output:**
120125
> ```py
121-
> >>> trigger # some example that makes it easy to unveil the magic
122-
> # some justified output
126+
> >>> 触发语句 # 一些让魔法变得容易理解的例子
127+
> # 一些正常的输入
123128
> ```
124129
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.
130+
**注意:** 所有的示例都在 Python 3.5.2 版本的交互解释器上测试过, 如果不特别说明应该适用于所有 Python 版本.
126131
127-
# Usage
132+
# Usage/用法
128133
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.
134+
我个人建议, 最好依次阅读下面的示例, 并对每个示例:
135+
- 仔细阅读设置例子最开始的代码. 如果您是一位经验丰富的 Python 程序员, 那么大多数时候您都能成功预期到后面的结果.
136+
- 阅读输出结果,
137+
+ 确认结果是否如你所料.
138+
+ 确认你是否知道这背后的原理.
139+
- 如果不知道, 深呼吸然后阅读说明 (如果你还是看不明白, 别沉默! 可以在[这](https://github.com/satwikkansal/wtfPython)提个 issue).
140+
- 如果知道, 给自己点奖励, 然后去看下一个例子.
136141
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.
142+
PS: 你也可以在命令行阅读 WTFpython. 我们有 pypi 包 和 npm 包(支持代码高亮).(译: 这两个都是英文版的)
138143
139-
To install the npm package [`wtfpython`](https://www.npmjs.com/package/wtfpython)
144+
安装 npm [`wtfpython`](https://www.npmjs.com/package/wtfpython)
140145
```sh
141146
$ npm install -g wtfpython
142147
```
143148
144-
Alternatively, to install the pypi package [`wtfpython`](https://pypi.python.org/pypi/wtfpython)
149+
或者, 安装 pypi [`wtfpython`](https://pypi.python.org/pypi/wtfpython)
145150
```sh
146151
$ pip install wtfpython -U
147152
```
148153

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

151156
---
152157

153-
# 👀 Examples
158+
# 👀 Examples/示例
154159

155160

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

158163
### > Strings can be tricky sometimes/微妙的字符串 *
159164

@@ -1234,7 +1239,7 @@ a, b = a[b] = {}, 5
12341239

12351240
---
12361241

1237-
## Section: Appearances are deceptive!
1242+
## Section: Appearances are deceptive!/外表是靠不住的!
12381243

12391244
### > Skipping lines?/跳过一行?
12401245

@@ -1343,7 +1348,7 @@ def square(x):
13431348

13441349
---
13451350

1346-
## Section: Watch out for the landmines!
1351+
## Section: Watch out for the landmines!/小心地雷!
13471352

13481353

13491354
### > Modifying a dictionary while iterating over it/迭代字典时的修改
@@ -1898,7 +1903,7 @@ tuple()
18981903
---
18991904

19001905

1901-
## Section: The Hidden treasures!
1906+
## Section: The Hidden treasures!/隐藏的宝藏!
19021907

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

@@ -2169,10 +2174,10 @@ True
21692174

21702175
---
21712176

2172-
## Section: Miscellaneous
2177+
## Section: Miscellaneous/杂项
21732178

21742179

2175-
### > `+=` is faster/更快的 `+=`
2180+
### > `+=` is faster/更快的 `+=`
21762181

21772182
```py
21782183
# 用 "+" 连接三个字符串:
@@ -2375,17 +2380,17 @@ nan
23752380

23762381
---
23772382

2378-
# Contributing
2383+
# Contributing/贡献
23792384

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

2382-
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)
2387+
你可以通过新建 [issue](https://github.com/satwikkansal/wtfpython/issues/new) 或者在上 [Gitter](https://gitter.im/wtfpython/Lobby) 与我们进行讨论.
23832388

2384-
# Acknowledgements
2389+
# Acknowledgements/致谢
23852390

2386-
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.
2391+
这个系列最初的想法和设计灵感来自于 Denys Dovhan 的项目 [wtfjs](https://github.com/denysdovhan/wtfjs). 社区的强大支持让它成长为现在的模样.
23872392

2388-
#### Some nice Links!
2393+
#### Some nice Links!/一些不错的资源
23892394
* https://www.youtube.com/watch?v=sH4XF6pKKmk
23902395
* https://www.reddit.com/r/Python/comments/3cu6ej/what_are_some_wtf_things_about_python
23912396
* https://sopython.com/wiki/Common_Gotchas_In_Python
@@ -2394,7 +2399,7 @@ The idea and design for this collection were initially inspired by Denys Dovhan'
23942399
* https://www.python.org/doc/humor/
23952400
* https://www.codementor.io/satwikkansal/python-practices-for-efficient-code-performance-memory-and-usability-aze6oiq65
23962401

2397-
# 🎓 License
2402+
# 🎓 License/许可
23982403

23992404
[![CC 4.0][license-image]][license-url]
24002405

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

2406-
## Help
2411+
## Help/帮助
24072412

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

2410-
## Surprise your geeky pythonist friends?
2415+
## Surprise your geeky pythonist friends?/想给你的极客朋友一个惊喜?
24112416

2412-
You can use these quick links to recommend wtfpython to your friends,
2417+
您可以使用这些快链向 Twitter 和 Linkedin 上的朋友推荐 wtfpython,
24132418

24142419
[Twitter](https://twitter.com/intent/tweet?url=https://github.com/satwikkansal/wtfpython&hastags=python,wtfpython)
24152420
| [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.)
24162421

2417-
## Need a pdf version?
2422+
## Need a pdf version?/需要来一份pdf版的?
2423+
2424+
我收到一些想要pdf版本的需求. 你可以快速在[](https://satwikkansal.xyz/wtfpython-pdf/)获得.
24182425

2419-
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.
2426+
## Follow Commit/追踪Commit
24202427

2421-
## Follow Commit
2428+
这是中文版 fork 时所处的原库 Commit, 当原库更新时我会跟随更新.
24222429

24232430
[![Commit id][commit-image]][commit-url]
24242431

0 commit comments

Comments
 (0)