如果你对于形参和实参的概念还不太熟悉的话,请参考我的另一篇博客,关于各类形参和实参的介绍再来看这个。
在使用def来定义函数时候发现有各种形参,仔细阅读print()函数的源码发现如下:
*print(…)
print(value, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
1、*value(任性形参:可以传入任意多的变量。如果不加关键字的话会默认传入value)
其实封装的print函数就是一个典型的可变形参和关键字形参相结合的函数。
因此,如果我们可以以逗号分隔的形式,对print函数传入多个变量,变量会自动传入value中,而其它的参数则需要通过关键字形参的方式传入
2、sep(可变形参):各个变量之间的分隔符号
如果不传入新的sep值,默认等于空字符串。