python传递任意数量的实参

#!/usr/bin/python
#coding=utf-8
#好好学习,天天向上
def make_pizza(*toppings):
    print("\nmaking a pizza with the following toppings:")
    for topping in toppings:
        print(f"-{topping}")
make_pizza('grafana')
make_pizza('tiger','jenkins','database','linux','windows')
#*toppings为形参。让python创建一个名为toppings的空元组,并将接受到的多个实参全部封装到这个元组当中

  python传递任意数量的实参

 

上一篇:python基础部分语法


下一篇:《Python从入门到实践》--第七章 while循环 课后练习