尝试学习Python /编程,我对类/继承有疑问。我创建了一个“ Media”类,并且想要创建一个名为“ Movie”的实例以从Media继承。对于Media,我已经将发布者的硬编码始终设置为等于“ Universal Studios”,因此我想让我的电影打印出Publisher,然后让其打印出“ Universal Studios”,但我对实现这一目标感到困惑。我在下面有我的代码,并尝试了各种语法,但无法弄清楚。
class Media:
def __init__(self, publisher = 'Universal Studios', market = 'USA'):
self.publisher = publisher
self.market = market
def get_media_info(self):
print(self.publisher, self.market)
return None
class Movie(Media):
def __init__(self, movie_data):
super().__init__(movie_data)
self.movie_data = movie_data
def test(self):
print(publisher)
test = Movie(movie_data = {'title': 'one', 'rating': 'two'})
test.test()