Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What are the ways to write a function using call by reference?

Answer Posted / chaitanya

Arguments in python are passed as an assignment. This assignment creates an object that has no relationship between an argument name in source and target. The procedure to write the function using call by reference includes:

The tuple result can be returned to the object which called it. The example below shows it:

def function(a, b):

a = 'value'

b = b + 1

# a and b are local variables that are used to assign the new objects

return a, b

# This is the function that is used to return the value stored in b

• The use of global variables allows the function to be called as reference but this is not the safe method to call any function.

• The use of mutable (they are the classes that consists of changeable objects) objects are used to pass the function by reference.

def function(a):

a[0] = 'string'

a[1] = a[1] + 1

# The ‘a’ array give reference to the mutable list and it changes the changes that are shared

args = ['string', 10]

func1(args)

print args[0], args[1]

#This prints the value stored in the array of ‘a’

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Give an example of a shuffle() method?

775


What is dogpile effect? How can you prevent this effect?

827


What are classes in python?

752


How would you work with numbers other than those in the decimal number system?

791


Explain inheritance in python with example?

754


How do you clear a python shell?

799


Why is python used?

769


What does defined by whitespace in python?

949


What is set type in python?

775


What is list comprehension how to define it and when to use?

815


How do you convert a string to in python?

805


Which server is used for python?

802


What is file context manager?

904


What data types does python support?

959


What is an abstract class in python?

849