标签:another 个人 through com AMM key shell 发送 测试
并不是必须写成 *args 和 **kwargs 。只有变量前?的*(星号)才是必须的.你也可以写成*var和**vars,?写成*args和**kwargs只是?个通俗的命名约定。
预先并不知道,函数使?者会传递多少个参数给你,所以在这个场景下使?这两个关键字。
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
def greet_me(**kwargs):
for key, value in kwargs.items():
print("{0} == {1}".format(key, value))
>>> greet_me(name="yasoob")
name == yasoob
def test_args_kwargs(arg1, arg2, arg3):
print("arg1:", arg1)
print("arg2:", arg2)
print("arg3:", arg3)
# ?先使? *args
>>> args = ("two", 3, 5)
>>> test_args_kwargs(*args)
arg1: two
arg2: 3
arg3: 5
# 现在使? **kwargs:
>>> kwargs = {"arg3": 3, "arg2": "two", "arg1": 5}
>>> test_args_kwargs(**kwargs)
arg1: 5
arg2: two
arg3: 3
import someclass
def get_info(self, *args):
return "Test data"
someclass.get_info = get_info
资料来源:《python进阶》
网盘地址:链接:https://pan.baidu.com/s/1auPpCQHMt6rrSR6jAPammQ
提取码:o3t2
仅作个人记录
标签:another 个人 through com AMM key shell 发送 测试
原文地址:https://www.cnblogs.com/fenxiangyuan/p/11830782.html