Python ã§ã¹ã¼ãã¼ã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã¡ã½ãããå¼ã³åºãã¨ãã«ä½¿ãã super() é¢æ°ã®ä½¿ãæ¹ããç´¹ä»ãã¾ãã Python 3 ã®å ´å ã¾ãã¯ä¾ãè¦ã¦ãã ããã class Dog: def __init__(self, name): self.name = name class UltraDog(Dog): def __init__(self, name, type_): super().__init__(name) self.type = type_ ud1 = UltraDog("taro", "akita") print(ud1.name) ãã®ã³ã¼ãã§ã¯ã Dog ã®ãµãã¯ã©ã¹ UltraDog ã® __init__() ã¡ã½ããã®ä¸ã§ super().__init__(name) ã¨ããæ¸ãæ¹ã使ã£ã¦ã¹ã¼ãã¼ã¯ã©ã¹ Dog ã® __init__() ã¡ã½ãããå¼ã³åº
Pythonã§ç¶æ¿ããã¯ã©ã¹ãåºåºã¯ã©ã¹ã®ã¡ã½ãããå¼ã³åºãããå ´åã« 2種é¡ã®æ¹æ³ãããããã§ãã # -*- coding: cp932 -*- class A(object): def test(self, x): return x class B(A): def test2(self, x): return super(B, self).test(x) #superé¢æ°ã使ã£ã¦Bã®ä¸ä½ã¯ã©ã¹ãå¼ã³åºã def test3(self, x): return A.test(self, x) #Aã®ã¤ã³ã¹ã¿ã³ã¹.test(x)ã¨åã if __name__ == '__main__': b = B() print b.test2('abc') print b.test3('def') å®è¡çµæã¯ä¸ã®ããã«ãªãã¾ãã abc defPythonã©ã¤ãã©ãªãªãã¡ã¬ã³ã¹ã§ã®superé¢æ°ã®èª¬æ
ã©ã³ãã³ã°
ã©ã³ãã³ã°
ã©ã³ãã³ã°
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}