Several methods of calling a function

# *args: accepts N positional arguments, converted to tuple form 
# def test(*args): 
#      print(args)
#
# test(1,2,3,4,5,5)
# test(*[1,2,4,5,5])#  args=tuple([1,2,3,4,5])

# def test1(x,*args):
#     print(x)
#     print(args)
#
# test1(1,2,3,4,5,6,7)


# **kwargs: accepts N keyword arguments and converts them to a dictionary 
# def test2(**kwargs): 
#      print(kwargs) 
#      print(kwargs['name']) 
#      print(kwargs['age'] ) 
#      print(kwargs['sex'])
#
# test2(name='alex',age=8,sex='F')
# test2(**{'name':'alex','age':8})
# def test3(name,**kwargs):
#     print(name)
#     print(kwargs)
#
# test3('alex',age=18,sex='m')

# def test4(name,age=18,**kwargs):
#     print(name)
#     print(age)
#     print(kwargs)
#
# test4('alex',age=34,sex='m',hobby='tesla')

def test4(name,age=18,*args,**kwargs):
    print(name)
    print(age)
    print(args)
    print(kwargs)
    logger("TEST4")

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325168458&siteId=291194637