Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Create your own:</p> <pre><code>def noop(*args, **kw): pass </code></pre> <p>This takes any number of positional and keyword arguments and does nothing at all. <a href="http://docs.python.org/2/reference/simple_stmts.html#grammar-token-pass_stmt" rel="nofollow noreferrer"><code>pass</code> signifies an empty python block</a>; it works anywhere Python expects a <code>block</code>, including loops, <code>if</code> statements and <code>try</code> statements.</p> <p>Python callables always return <em>something</em> (it is a language requirement); if no explicit return value is given <code>None</code> is returned.</p> <p>The <code>*</code> and <code>**</code> indicate arbitrary length parameters; you can pass in 0 or more positional parameters and the <code>args</code> name will represent a tuple of them, and 0 or more keyword arguments, and they are captured in the <code>kw</code> dictionary.</p> <p>From the <a href="http://docs.python.org/2/reference/compound_stmts.html#function-definitions" rel="nofollow noreferrer">function definition documentation</a>:</p> <blockquote> <p>If the form “<code>*identifier</code>” is present, it is initialized to a tuple receiving any excess positional parameters, defaulting to the empty tuple. If the form “<code>**identifier</code>” is present, it is initialized to a new dictionary receiving any excess keyword arguments, defaulting to a new empty dictionary.</p> </blockquote> <p>Simple demo of <code>*</code> and <code>**</code> parameters:</p> <pre><code>&gt;&gt;&gt; def f(*args, **kw): return (args, kw) ... &gt;&gt;&gt; f('foo', 'bar', spam='eggs', monty='python') (('foo', 'bar'), {'monty': 'python', 'spam': 'eggs'}) </code></pre> <p>For functional programming, if you need the arguments to be returned <em>as is</em> you need to think about what you need returning; a one-argument function would return just that argument and for anything that needs to take 2 or more arguments and return them all, you'd have to return those arguments as a tuple:</p> <pre><code>def identity(arg): return arg def plural_identity(*args): return args </code></pre> <p>Demo:</p> <pre><code>&gt;&gt;&gt; identity('foobar') 'foobar' &gt;&gt;&gt; plural_identity('spam', 'eggs') ('spam', 'eggs') </code></pre>
    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. 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