How to chain functions? : <p>I am trying to understand the mechanics of chained functions such as</p>

<pre><code>&gt;&gt;&gt; 'hello'.upper()
'HELLO'
</code></pre>

<p>(the chain can be longer, I do not have a good example in my head right now - something like <code>'hello'.upper().reverse().take_every_second_character().rot13()</code>)</p>

<p>How is this functionality achieved? What must be returned by each of the functions (and intercepted (= used as a parameter?) by the next one), taken into account that one can break the chain somewhere and still get an output? To take the fictional example above:</p>

<pre><code>&gt;&gt;&gt; 'hello'
'hello'

&gt;&gt;&gt; 'hello'.upper()
'HELLO'

&gt;&gt;&gt; 'hello'.upper().reverse()
'OLLEH'
</code></pre>

<p>etc.</p>
