<pre><codeclass="python language-python hljs">head, *body, tail = <coll.><spanclass="hljs-comment"># Head or tail can be omitted.</span>
</code></pre>
<div><h2id="inline"><ahref="#inline"name="inline">#</a>Inline</h2><div><h3id="lambda">Lambda</h3><pre><codeclass="python language-python hljs"><func> = <spanclass="hljs-keyword">lambda</span>: <return_value><spanclass="hljs-comment"># A single statement function.</span>
<func> = <spanclass="hljs-keyword">lambda</span><arg_1>, <arg_2>: <return_value><spanclass="hljs-comment"># Also accepts default arguments.</span>
<div><h2id="inline"><ahref="#inline"name="inline">#</a>Inline</h2><div><h3id="lambda">Lambda</h3><pre><codeclass="python language-python hljs"><func> = <spanclass="hljs-keyword">lambda</span>: <return_value><spanclass="hljs-comment"># A single statement function.</span>
<func> = <spanclass="hljs-keyword">lambda</span><arg_1>, <arg_2>: <return_value><spanclass="hljs-comment"># Also accepts default arguments.</span>
<pre><codeclass="python language-python hljs"><spanclass="hljs-meta">>>></span>[l+r <spanclass="hljs-keyword">for</span> l <spanclass="hljs-keyword">in</span><spanclass="hljs-string">'abc'</span><spanclass="hljs-keyword">for</span> r <spanclass="hljs-keyword">in</span><spanclass="hljs-string">'abc'</span>]
<li><strong>Reduce must be imported from the functools module.</strong></li>
</ul>
<div><h3id="anyall">Any, All</h3><pre><codeclass="python language-python hljs"><bool> = any(<collection>) <spanclass="hljs-comment"># Is `bool(el)` True for any element.</span>
<bool> = all(<collection>) <spanclass="hljs-comment"># Is True for all elements or empty.</span>
<div><h3id="anyall">Any, All</h3><pre><codeclass="python language-python hljs"><bool> = any(<collection>) <spanclass="hljs-comment"># Is `bool(el)` True for any element.</span>
<bool> = all(<collection>) <spanclass="hljs-comment"># Is True for all elements or empty.</span>
</code></pre></div>
<div><h3id="conditionalexpression">Conditional Expression</h3><pre><codeclass="python language-python hljs"><obj> = <exp_if_true><spanclass="hljs-keyword">if</span><condition><spanclass="hljs-keyword">else</span><exp_if_false><spanclass="hljs-comment"># Only one expression gets evaluated.</span>
<div><h3id="conditionalexpression">Conditional Expression</h3><pre><codeclass="python language-python hljs"><obj> = <exp><spanclass="hljs-keyword">if</span><condition><spanclass="hljs-keyword">else</span><exp><spanclass="hljs-comment"># Only one expression gets evaluated.</span>
</code></pre></div>
<pre><codeclass="python language-python hljs"><spanclass="hljs-meta">>>></span>[a <spanclass="hljs-keyword">if</span> a <spanclass="hljs-keyword">else</span><spanclass="hljs-string">'zero'</span><spanclass="hljs-keyword">for</span> a <spanclass="hljs-keyword">in</span> (<spanclass="hljs-number">0</span>, <spanclass="hljs-number">1</span>, <spanclass="hljs-number">2</span>, <spanclass="hljs-number">3</span>)]
Point = namedtuple(<spanclass="hljs-string">'Point'</span>, <spanclass="hljs-string">'x y'</span>)
point = Point(<spanclass="hljs-number">0</span>, <spanclass="hljs-number">0</span>)
Point = namedtuple(<spanclass="hljs-string">'Point'</span>, <spanclass="hljs-string">'x y'</span>)<spanclass="hljs-comment"># Tuple's subclass with named elements.</span>
point = Point(<spanclass="hljs-number">0</span>, <spanclass="hljs-number">0</span>)<spanclass="hljs-comment"># Tuple with x and y attributes.</span>
Direction = Enum(<spanclass="hljs-string">'Direction'</span>, <spanclass="hljs-string">'n e s w'</span>)
direction = Direction.n
Direction = Enum(<spanclass="hljs-string">'Direction'</span>, <spanclass="hljs-string">'n e s w'</span>)<spanclass="hljs-comment"># Enum with n, e, s and w members.</span>
direction = Direction.n<spanclass="hljs-comment"># Member with name and value attributes.</span>
Player = make_dataclass(<spanclass="hljs-string">'Player'</span>, [<spanclass="hljs-string">'loc'</span>, <spanclass="hljs-string">'dir'</span>])<spanclass="hljs-comment"># Class with init, repr and eq methods.</span>
player = Player(point, direction) <spanclass="hljs-comment"># Object with loc and dir attributes.</span>
</code></pre>
<div><h2id="imports"><ahref="#imports"name="imports">#</a>Imports</h2><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">import</span><module><spanclass="hljs-comment"># Imports a built-in or '<module>.py'.</span>
<spanclass="hljs-keyword">import</span><package><spanclass="hljs-comment"># Imports a built-in or '<package>/__init__.py'.</span>