• What do you mean by *args and **kwargs?

    Answered

    What do you mean by *args and **kwargs?

    Silver Member Asked on June 4, 2018 in Python.
    Add Comment
  • 1 Answer(s)
    Best answer

    In cases when we don’t know how many arguments will be passed to a function, like when we want to pass a list or a tuple of values, we use *args.

    
    def func(*args):
    
    for i in args:
    
    print(i)
    
    func(3,2,1,4,7)
    
    

    **kwargs takes keyword arguments when we don’t know how many there will be.

    
    def func(**kwargs):
    
    for i in kwargs:
    
    print(i,kwargs[i])
    
    func(a=1,b=2,c=7)
    
    
    Silver Member Answered on June 4, 2018.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.