请问,为什么导入一个模块中的一个类,同一个模块中的另一个类会运行?

初学python

导入的模块:

class Restaurant:
def init(self,restaurant_name,cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type

def describe_restaurant(self):
    print(f"{self.restaurant_name}\n{self.cuisine_type}")

def open_restaurant(self):
    print(f"The restaurant {self.restaurant_name} is open. ")

class IceCreamStand(Restaurant):
def init(self,restaurant_name,cuisine_type):
super().init(restaurant_name,cuisine_type)
self.flavors = ['strawberry','watermellon','apple']

def describe_flavors(self):
    for key in self.flavors:
        print(key)

IceCreamStand_1 = IceCreamStand('Alice','sweet')
IceCreamStand_1.describe_flavors()

被导入:
from practice9_6 import Restaurant

运行结果:

strawberry
watermellon
apple

代码有些乱, 层次看不清。建议用插入代码功能重新贴一下代码

img



```python
class Restaurant:
    def __init__(self,restaurant_name,cuisine_type):
        self.restaurant_name = restaurant_name
        self.cuisine_type = cuisine_type

    def describe_restaurant(self):
        print(f"{self.restaurant_name}\n{self.cuisine_type}")

    def open_restaurant(self):
        print(f"The restaurant {self.restaurant_name} is open. ")


class IceCreamStand(Restaurant):
    def __init__(self,restaurant_name,cuisine_type):
        super().__init__(restaurant_name,cuisine_type)
        self.flavors = ['strawberry','watermellon','apple']

    def describe_flavors(self):
        for key in self.flavors:
            print(key)


IceCreamStand_1 = IceCreamStand('Alice','sweet')
IceCreamStand_1.describe_flavors()


from practice9_6 import Restaurant
```python