Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Calling a Function in python and Pass by reference and value

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 722
    Comment on it

    When we define a function only gives it a name, specifies the parameters that are to be included in the function and structures the blocks of code and refer to that value .In calling function you have to define specifies parameters.For example you can see below code.


     

    # Function definition is here
    def printfindnerd( str ):
       "This prints a passed string into this function with findnerd string name"
       print str
       return;
    
    # Now you can call printme function and define it.
    printme("we are first call to user defined function!")
    printme("And again we are second call to the same function")
    Output  
    we are first call to user defined function!
    And again we are second call to the same function
    Pass by reference and value->
    In pass by reference and value we have to define  parameters (arguments) in the Python language are passed by reference.tAnd we can change what a parameter refers to within a function, the change also reflects back in the calling function and set the value. For example you can see below code.
    
    def demome( mylist ):
       "This changes a passed list into this function and set the value"
       mylist.append([1,2,3,4,5,6]);
       print "Values inside the function: ", mylist
       return
    
    # Now you can call changeme function
    mylist = [10,20,30,40];
    changeme( mylist );
    print "Values outside the function: ", mylist
    Output-> Values inside the function:  [10, 20, 30,40, [1, 2, 3, 4,5,6]]
    Values outside the function:  [10, 20, 30,40, [1, 2, 3, 4,5,6]]
    
    
    

     

 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: