python函数-结合使用位置实参和任意数量实参

次阅读
def make_pizza(size, *toppings):
    """打印顾客点的所有配料"""
    print("\nMaking a {}-inch pizza with the following toppings:".format(size))
    for topping in toppings:
        print(f"-{topping}")

make_pizza(16, 'pepperoni')
make_pizza(12, 'mushrooms', 'green peppers', 'extra cheese')
Making a 16-inch pizza with the following toppings:
-pepperoni

Making a 12-inch pizza with the following toppings:
-mushrooms
-green peppers
-extra cheese


相关文章:

版权声明:由yongbin2023-10-25 18:00:59发表,共计544字。
新手QQ群: 703975885,欢迎进群讨论 鲁班编程网