Tuesday, September 15, 2009

Python - multiple inheritance

<pre>
<span class="comment"># multiple inheritance with python....its easy!span>
<span class="comment"># in addition to multiple inheritance you shouldspan>
<span class="comment">#   check out the creating static methods for a classspan>

<span class="ANY_KEYWORD">classspan> Arm(object):
    <span class="ANY_KEYWORD">defspan> flipBird(self):
        <span class="ANY_KEYWORD">printspan> <span class="STRING_LITERAL">&quot;span><span class="STRING_LITERAL">extend middle fingerspan><span class="STRING_LITERAL">&quot;span>


<span class="ANY_KEYWORD">classspan> Weapon(object):
    <span class="ANY_KEYWORD">defspan> fireWeapon(self):
        <span class="ANY_KEYWORD">printspan> <span class="STRING_LITERAL">&quot;span><span class="STRING_LITERAL">rat tat tatspan><span class="STRING_LITERAL">&quot;span>
<span class="comment"># with your span><span class="comment">powers combined I am Hero Arm (part arm part weapon!)span>
<span class="ANY_KEYWORD">classspan> HeroArm(Arm, Weapon):
    <span class="ANY_KEYWORD">passspan>


a = HeroArm()

a.fireWeapon()

<span class="comment">#output:span>
<span class="comment"># rat tat tatspan>

a.flipBird()
<span class="comment">#outputspan>
<span class="comment"># extend middle fingerspan>

pre>

No comments:

Post a Comment