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

orenma
  • 1,163
  • 2
  • 10
  • 19

1 Answers1

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.

Maxime Chéramy
  • 17,761
  • 8
  • 54
  • 75