0

I have 2 function that use the same variable, like this:

some_function():
    #do something with MyDict
    MyDict = dict()
    MyDict['name'] = 'hallo'

main():
    #do something else with MyDict
    MyDict['age'] = 33
    some_function()

I don't want to use global and let say that MyDict is very big and I don't want to pass it to some_function. what is the best way to do so? there is a way to pass a pointer to MyDict? PS: I'm using py3.2

1 Answer 1

1

In short: when you pass a dict as argument to a function, only the reference is passed, the data is not copied.

However, in general the parameters are references but some types are mutables but others aren't which changes the behavior.

Sign up to request clarification or add additional context in comments.

1 Comment

For more clarification, @orenma you should take a look at this answer - stackoverflow.com/a/986145/2689986

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.