<p>除了<a href="https://stackoverflow.com/a/13853409/505154">BrenBarn's excellent answer</a>中提供的信息外,您会发现许多Python程序员坚持总是使用<code>def</code>而不是{<cd2>},因此我将尝试解释为什么会这样。在</p>
<p>基本上可以从<a href="https://stackoverflow.com/questions/228181/the-zen-of-python">Zen of Python</a>归结为以下一行:</p>
<blockquote>
<p>There should be one-- and preferably only one --obvious way to do it.</p>
</blockquote>
<p>这在<a href="http://www.artima.com/weblogs/viewpost.jsp?thread=98196" rel="nofollow noreferrer">Guido van Rossum's post about this issue</a>中引用(Guido是Python的创建者):</p>
<blockquote>
<p>Why drop lambda? Most Python users are unfamiliar with Lisp or Scheme, so the name is confusing; also, there is a widespread misunderstanding that lambda can do things that a nested function can't -- I still recall Laura Creighton's Aha!-erlebnis after I showed her there was no difference! Even with a better name, I think having the two choices side-by-side just requires programmers to think about making a choice that's irrelevant for their program; not having the choice streamlines the thought process. Also, once map(), filter() and reduce() are gone, there aren't a whole lot of places where you really need to write very short local functions; Tkinter callbacks come to mind, but I find that more often than not the callbacks should be methods of some state-carrying object anyway (the exception being toy programs).</p>
</blockquote>