Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>lambda</code> clearly is a keyword; it's a special word recognised by the parser, which would otherwise fall within the definition of an <code>identifier</code>.</p> <p><code>lambda</code> is not <em>semantically</em> an operator. An operator is just a function, but invoked with a different syntax. We can imagine replacing the <code>+</code> operator with an <code>add</code> function; all our programs with addition would get more verbose and harder to read, but we could still write them. The <code>lambda</code> language construct on the other hand could not be replaced with a function; <code>lambda x: x+1</code> is not just calculating a result from the values <code>x</code> and <code>x+1</code>, because in this context they are not values at all (<code>x</code> is the name of the parameter to the function being defined, and <code>x+1</code> is the code of the lambda body).</p> <p>In the same page you linked to we have: <a href="http://docs.python.org/py3k/reference/lexical_analysis.html#operators" rel="nofollow">http://docs.python.org/py3k/reference/lexical_analysis.html#operators</a></p> <blockquote> <p>The following tokens are operators:</p> <pre><code>+ - * ** / // % &lt;&lt; &gt;&gt; &amp; | ^ ~ &lt; &gt; &lt;= &gt;= == != </code></pre> </blockquote> <p>That's the entire contents of the subsection on operators. From this I take it to mean that in the context of defining the tokens of the language "operators" are symbolic operators, whereas the section on <em>keywords</em> is explicitly spelling out that "these things which would otherwise be identifiers are keywords". That's why I think the keyword operators like <code>not</code>, <code>is</code>, <code>in</code>, etc are not listed. But there certainly are things that are semantically operators that are keywords, whether or not the parser considers them separate classes.</p> <p>I'm not sure why <a href="http://docs.python.org/py3k/reference/expressions.html#summary" rel="nofollow">http://docs.python.org/py3k/reference/expressions.html#summary</a> describes <code>lambda</code> as an operator; I certainly wouldn't. Strictly speaking it doesn't explicitly say "<code>lambda</code> is the operator with the lowest precedence", it just lists <code>lambda</code> in a table whose column heading is "Operator". Perhaps it was just a convenience; describing <code>lambda</code> as a thing with low precedence is a good way of clarifying how Python will parse <code>lambda x: x + 1</code> (it could theoretically be either <code>(lambda x: x) + 1</code> or <code>lambda x: (x + 1)</code>).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload