Этот код сбивает меня с толку.Почему вы переопределяете Restaurant
?Это должно работать:
class Restaurant:
"""описание ресторана"""
def __init__(self, restaurant_name, cuisine_type):
"""Инициализирует атрибуты restaurant_name и cuisine_type."""
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print(self.restaurant_name.title())
print(self.cuisine_type.title())
def open_restaurant(self):
print("Restaurant is open now!")
Мы определили класс.Давайте создадим его экземпляр:
r = Restaurant('x', 'y')
Теперь давайте вызовем определенный метод:
r.open_restaurant() # Restaurant is open now!
И наоборот, если вы хотите вызвать open_restaurant()
без создания экземпляра класса, вы можете определить @staticmethod
:
class Restaurant:
"""описание ресторана"""
def __init__(self, restaurant_name, cuisine_type):
"""Инициализирует атрибуты restaurant_name и cuisine_type."""
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print(self.restaurant_name.title())
print(self.cuisine_type.title())
@staticmethod
def open_restaurant():
print("Restaurant is open now!")
И тогда вы можете просто позвонить:
open_restaurant() # Restaurant is open now!