Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><p><code>exec</code> is not an expression: a statement in Python 2.x, and a function in Python 3.x. It compiles and immediately evaluates a statement or set of statement contained in a string. Example:</p> <pre><code>exec('print(5)') # prints 5. # exec 'print 5' if you use Python 2.x, nor the exec neither the print is a function there exec('print(5)\nprint(6)') # prints 5{newline}6. exec('if True: print(6)') # prints 6. exec('5') # does nothing and returns nothing. </code></pre></li> <li><p><code>eval</code> is a built-in function (<strong>not</strong> a statement), which evaluates an expression and returns the value that expression produces. Example:</p> <pre><code>x = eval('5') # x &lt;- 5 x = eval('%d + 6' % x) # x &lt;- 11 x = eval('abs(%d)' % -100) # x &lt;- 100 x = eval('x = 5') # INVALID; assignment is not an expression. x = eval('if 1: x = 4') # INVALID; if is a statement, not an expression. </code></pre></li> <li><p><code>compile</code> is a lower level version of <code>exec</code> and <code>eval</code>. It does not execute or evaluate your statements or expressions, but returns a code object that can do it. The modes are as follows:</p> <ol> <li><code>compile(string, '', 'eval')</code> returns the code object that would have been executed had you done <code>eval(string)</code>. Note that you <em>cannot</em> use statements in this mode; only a (single) expression is valid.</li> <li><code>compile(string, '', 'exec')</code> returns the code object that would have been executed had you done <code>exec(string)</code>. You can use any number of statements here.</li> <li><code>compile(string, '', 'single')</code> is like the <code>exec</code> mode, but it will ignore everything except for the first statement. Note that an <code>if</code>/<code>else</code> statement with its results is considered a single statement.</li> </ol></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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