当前位置:网站首页>Super (subclass)__ init__ And parent class__ init__ ()

Super (subclass)__ init__ And parent class__ init__ ()

2022-06-11 05:50:00 Lao Liu selling vegetables at the corner of the street

'''
super Can refer to parent class .
have access to super Key word call init Method ,
Grammar format :super( Subclass ,self).__init__( Parameters 1, Parameters 2,…)
The effect is equivalent to : Parent class name .__init__(self, Parameters 1, Parameters 2,…)
'''
For example, it is commonly used in aircraft wars :

# pygame.sprite.Sprite.__init__(self) # Call the initial method of the parent class 
super(Bullet,self).__init__() # The upper and lower levels are the same. They all call the methods of the parent class 

 

These two lines of code are the same

原网站

版权声明
本文为[Lao Liu selling vegetables at the corner of the street]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020533537918.html