【发布时间】:2020-01-16 14:46:24
【问题描述】:
我遇到了一个代码,它以两种不同的方式使用super() 方法,我不明白逻辑上有什么区别。
我现在正在学习 pygame 模块,我的任务是创建一个 Ball 的类,它继承自 Sprite,这是 pygame 模块的一个类(如果我不是错误)。
我遇到了这段代码:
import pygame
class Ball(pygame.sprite.Sprite):
def __init__(self, x, y):
super(Ball, self).__init__()
我无法理解与以下内容的区别:
import pygame
class Ball(pygame.sprite.Sprite):
def __init__(self, x, y):
super().__init__()
(super()方法的参数)
这些代码块的逻辑有什么区别?为什么我需要传递给super() 方法参数?这些论点是什么?
【问题讨论】:
标签: python python-3.x class pygame super