私はPythonでOOPを学んでいます。Pythonでの継承の理解
これは私が意図したとおりに動作しない理由は苦労していますか?
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]: ''
USPatentインスタンスでkcを取得できないように私が明らかにしている間違いは何ですか?ここで
私はまだKC = KCの使用を理解していないのですか? – Rahul
@Rahul:あなたの関数に 'print(CC、PN、KC)'を追加すれば助けになるでしょうか?あなたは値に何が起こるか見るでしょう。 –
@Rahul 'KC =" "は、[デフォルトのキーワード引数で関数を定義する](https://docs.python.org/3/tutorial/controlflow.html#more-on-defining-functions )([キーワード引数を持つ関数を呼び出す](https://docs.python.org/3/tutorial/controlflow.html#keyword-arguments)とは対照的です)。 – tutuDajuju