什么是dunder?

2020年6月29日 / 22次阅读 / Last Modified 2020年6月29日
故事

阅读python文档,常常看到dunder这个词,查字典,无!晕死......今天终于找到了这个词的出处。

原来dunder是 Double UNDERscore(中文双下划线)的缩写,分别取Double的D 和 Underscore的Under组成。这样取名后方便发音。

在发明 dunder 之前, __init__ 要念作 double underscore init,其中的double underscore 有17个单词,发音是6声(嘴或舌头要变换7次动作,你可以以试试),而dunder 只有6个单词,发音是2声。大大降低了手和嘴的劳动量,这个好的发明,当然举双手占成了。

python官方的wiki做如下说明:

Dunder (Double UNDERscore) Alias
Mark Jackson was the first to suggest dunder as a speech shorthand for double underscores (__) in a reply to a query from Pat Notz. Ned Batchelder later stressed the need for a way of pronouncing __:
An awkward thing about programming in Python : there are lots of double underscores. [snip] My problem with the double underscore is that it's hard to say. How do you pronounce __init__? "underscore underscore init underscore underscore"? "under under init under under"? Just plain "init" seems to leave out something important. I have a solution: double underscore should be pronounced "dunder". So __init__ is "dunder init dunder", or just "dunder init".

PEP8中就有对dunder的说明,现在知道在说什么了。

-- EOF --

本文链接:https://www.pynote.net/archives/2094

留言区

电子邮件地址不会被公开。 必填项已用*标注


前一篇:
后一篇:

More


©Copyright 麦新杰 Since 2019 Python笔记

go to top