Understanding Inheritance in python
<p>I am learning OOP in python.</p>

<p>I am struggling why this is not working as I intended?</p>

<pre><code>class Patent(object):
    """An object to hold patent information in Specific format"""
    def __init__(self, CC, PN, KC=""):
        self.cc = CC
        self.pn = PN
        self.kc = KC

class USPatent(Patent):
    """"Class for holding information of uspto patents in Specific format"""
    def __init__(self, CC, PN, KC=""):
        Patent.__init__(self, CC, PN, KC="")


pt1 = Patent("US", "20160243185", "A1")

pt2 = USPatent("US", "20160243185", "A1")

pt1.kc
Out[168]: 'A1'

pt2.kc
Out[169]: ''
</code></pre>

<p>What obvious mistake I am making so that I am not able to get kc in USPatent instance?</p>

<p>You are passing in an empty string:</p>

<pre><code>Patent.__init__(self, CC, PN, KC="")
</code></pre>

<p>That calls the <code>Patent.__init__()</code> method setting <code>KC</code> to <code>""</code>, always.</p>

<p>Pass in whatever value of <code>KC</code> you received instead:</p>

<pre><code>class USPatent(Patent):
    """"Class for holding information of uspto patents in Specific format"""
    def __init__(self, CC, PN, KC=""):
        Patent.__init__(self, CC, PN, KC=KC)
</code></pre>

<p>Within <code>USPatent.__init__()</code>, <code>KC</code> is just another variable, just like <code>self</code>, <code>CC</code> and <code>PN</code>. It is either set to <code>""</code> already, or to whatever was passed in when you call <code>USPatent(...)</code> with arguments. You simply want to call the <code>Patent.__init__()</code> method passing on all the values you have.</p>

<p>You can drop the keyword argument syntax from the call too:</p>

<pre><code>Patent.__init__(self, CC, PN, KC)
</code></pre>

python inheritance