Python lambda function "translation" causes recursion error
<p>While attempting to understand python lambda functions, I "translated" this function:</p>

<pre><code>s = lambda y: y ** y; s(3)  
</code></pre>

<p>Into this regular, defined function:</p>

<pre><code>def power_of_self(y):
    return y ** y
power_of_self(3)
</code></pre>

<p>When I tried running it as a script (<code>python lambda_stuff.py</code>) I had no problem. However, when attempting to run it via the Python shell, this weird thing happened:</p>

<pre><code>&gt;&gt;&gt; def power_of_self(y):
...     return y ** y
... power_of_self(3)
File "&lt;stdin&gt;", line 3
power_of_self(3)
            ^
SyntaxError: invalid syntax
&gt;&gt;&gt; print power_of_self(3)
Traceback (most recent call last):
File "&lt;stdin&gt;", line 1, in &lt;module&gt;
File "&lt;stdin&gt;", line 1, in power_of_self
File "&lt;stdin&gt;", line 1, in power_of_self
File "&lt;stdin&gt;", line 1, in power_of_self
File "&lt;stdin&gt;", line 1, in power_of_self
**A FEW HUNDRED MORE OF THESE**
RuntimeError: maximum recursion depth exceeded
</code></pre>

<p>Why did my script execution differ from my shell execution? I wonder if the <code>...</code> had anything to do with it.</p>

<p>Your function is still been defined in the shell. Hit an extra <kbd>Enter</kbd> before calling the function.</p>

python lambda