Inplace functions in Python
<p>In Python there is a concept of inplace functions. For example shuffle is inplace in that it returns none.</p>

<p>How do I determine if a function will be inplace or not?</p>

<pre><code>from random import shuffle

print(type(shuffle))

&lt;class 'method'&gt;
</code></pre>

<p>So I know it's a <code>method</code> from class <code>random</code> but is there a special variable that defines some functions as inplace?</p>

<p>You can't have a-priory knowledge about the operation for a given function. You need to either look at the source and deduce this information, or, examine the docstring for it and hope the developer documents this behavior.</p>

<p>For example, in <code>list.sort</code>:</p>

<pre><code>help(list.sort)
Help on method_descriptor:

sort(...)
    L.sort(key=None, reverse=False) -&gt; None -- stable sort *IN PLACE*
</code></pre>

<p>For functions operating on certain types, their mutability generally lets you extract some knowledge about the operation. You can be certain, for example, that all functions operating on strings will eventually return a new one, meaning, they can't perform in-place operations.</p>

python function python-3.x