📜  在 Python 类的多个实例中使用变量 - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:22.782000             🧑  作者: Mango

代码示例1
class CoffeeOrder:
    def __init__(self, coffee_name, price):
        self.coffee_name = coffee_name
        self.price = price

lucas_order = CoffeeOrder("Espresso", 2.10)
print(lucas_order.coffee_name)
print(lucas_order.price)

paulina_order = CoffeeOrder("Latte", 2.75)
print(paulina_order.coffee_name)
print(paulina_order.price)