Positional Arguments

1. Positional Arguments 

  • These are the arguments passed to a function in correct positional order.

  • The number of arguments and their positions in the function definition should match exactly with the number and position of the arguments in the function call.

  • If we change the number of arguments then we will get error.  

2. Keyword Arguments

  • Keyword arguments are arguments that identify the parameters by their names.

  • We can pass argument values by keyword i.e by parameter name. 

  • Here the order of arguments is not important but number of arguments must be matched.


Note:- We can use both positional and keyword arguments simultaneously. But first we have to take positional arguments and then keyword arguments,otherwise we will get SyntaxError. 

            def wish(name,msg):  
                 print("Hello",name,msg) 
            wish("Programmerfect","Good Morning")      ==>valid 
            wish("Programmerfect",msg="Good Morning")     ==>valid 
            wish(name="Programmerfect","Good Morning")   ==>invalid       
            SyntaxError: positional argument follows keyword argument

              

Comments