先来js版的不定参数
function test_var_args(f_arg,...argv) {
console.log('first normal arg:',f_arg);
for(let arg of argv){
console.log("another arg through *argv:", arg);
}
}
test_var_args('yasoob', 'python', 'eggs', 'test');
再来python版本的
def test_var_args(f_arg, *argv):
print("first normal arg:", f_arg)
for arg in argv:
print("another arg through *argv:", arg)
test_var_args('yasoob', 'python', 'eggs', 'test')
输出结果都是:
first normal arg: yasoob
another arg through *argv: python
another arg through *argv: eggs
another arg through *argv: test