1、函数传入实参,可变参数(*)之前的参数不能指定参数名。
>>> def myfun(a, *b): ... print(a )... print(b) ... >>> myfun(a=1, 2,3,4) File "<stdin>", line 1 SyntaxError: positional argument follows keyword argument >>> myfun(1, 2,3,4) 1 (2, 3, 4)
2、函数传入实参,可变参数(*)之后的参数必须指定参数名,否则就会被归到可变参数之中。
>>> def myfun(a, *b, c=None): ... print(a) ... print(b) ... print(c) ... >>> myfun(1, 2,3,4) 1 (2, 3, 4) None >>> myfun(1, 2,3,c=4) 1 (2, 3) 4
以上就是python可变参数的使用注意,希望对大家有所帮助。更多Python学习指路:
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
Copyright © 2019- huatuowenda.com 版权所有 湘ICP备2023022495号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务