Python dictionary help

Trying to understand below about python dictionaries:

## Function 
def abc(gamer) :
    gamer['name']= 'Roger'
print(nm) ##Could not understand this output

This final print output returns {‘name’: ‘Roger’} but I expect to see {‘name’: ‘Sam’} as there has been no value returned from the function call. Much appreciated if experts can help explain the same.

dictionary are passed by reference, not by value.

so the dictionary exists in memory, python provides the memory address, the function will then update the dictionary in memory.

1 Like

Thanks for clarifying and refreshing the memory, I guess with lists and dictionaries the concept of Mutable structures comes into play.

not only that, there is also a difference between arguments being passed by value (integers, floats, string) and reference (list, dictionaries)

Python is written in C, to truly grasp this concept fully is to learn about C and pointers. Understanding that we only have one dictionary or list in memory. And python gives the address of this dictionary to the function.

unlike integers and floats, which value get copied and passed to the function.

I found a decent looking article:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.