下面我将用代码解释
def function(*args):
的用法 --- *args输入参数如何工作的:*args ```可以接受序列的输入参数。当函数的参数不确定时,可以使用 *args。
#!/usr/bin/python
# -*- coding: UTF-8 -*-
def biggest_number(*args):
print max(args)
return max(args)
def smallest_number(*args):
print min(args)
return min(args)
def distance_from_zero(arg):
print abs(arg)
return abs(arg)
biggest_number(-10, -5, 5, 10)
smallest_number(-10, -5, 5, 10)
distance_from_zero(-10)
程序输出结果:
C:\Users\douk\PycharmProjects\Python_Learn\venv\Scripts\python.exe C:/Users/douk/PycharmProjects/Python_Learn/Print_test.py
10
-10
10
Process finished with exit code 0
原文:http://blog.51cto.com/8587157/2069134