Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Function Arguments in Python

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.67k
    Comment on it

    In python function use the following types of formal arguments which is given below
    Required arguments-> Required arguments are the arguments passed to a function in correct positional order and the number of arguments used in the function call should match exactly with the function and arguments in program. For example you can see below code-

    def printme( str ):
       "Findnerd passed string into this function"
       print str
       return;
    
    # Now you can call printme function
    printme()
    Keyword arguments-> keyword arguments are related to the function calls and variable. When you use keyword arguments and variable in a function call, the caller identifies the arguments by the parameter name and varibale. For example you can see below code.
    def printme( str ):
       "Test passed string into this function"
       print str
       return;
    
    # Now you can call printme function
    printme( str = "Findnerd")
    Default arguments-> default argument is an argument that show a default value if a value is not provided in the function call for that argument and variable. For example you can see below code-
    def printinfo( Demo,Test ):
       "This prints a passed info into this function"
       print "Demo: ", demo
       print "Test ", test
       return;
    
    # Now you can call printinfo function
    printinfo( 'Demo, test' )
    printinfo( test )
    Variable-length arguments-> A variable-length arguments function are specified while defining the function and arguments. For example you can see below code.
     Function definition is here
    def printinfo( arg1, *vartuple ):
       "This prints a variable passed arguments"
       print "Output is: "
       print arg1
       for var in vartuple:
          print var
       return;
    
    # Now you can call printinfo function
    printinfo( 10 )
    printinfo( 70, 60, 50 )
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: