Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Although it may seem like your functions don't return anything, they do in fact. Quoting <a href="http://docs.python.org/tutorial/controlflow.html#defining-functions" rel="nofollow">the Python.org documentation</a>:</p> <blockquote> <p>The return statement returns with a value from a function. return without an expression argument returns None. Falling off the end of a function also returns None.</p> </blockquote> <p>So your functions really look like this:</p> <pre><code>def pants(): print "Put on some pants!" return None def shorts(): print "And don't forget your underwear!" return None </code></pre> <p>Your assignments assign to <code>zap</code> whatever <code>pants</code> returns (i.e. the value of <code>pants()</code>), and to <code>thing</code> whatever <code>shorts</code> returns. In your case, both are <code>None</code>, but of course the functions must be run in order to figure this out(*). Afterall, it could be that <code>pants</code> returns <code>42</code> during leap years, and that <code>shorts</code> returns <code>'Foobar'</code> whenever some random number generator "rolls" a 6.</p> <hr> <p>(*) Digression: That the functions "must be run" should not be considered universally true. In a <a href="https://en.wikipedia.org/wiki/Pure_function" rel="nofollow">pure setting</a>, and leaving aside the specifics of Python (of which I know very little), a compiler might realize that both functions are identically <code>None</code>, and cause no calls to be made when the program is run. But a function that prints something (or inspects whether the current year is a leap year, or rolls a die) won't be pure.</p>
    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.
    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