Trying to understand below about python dictionaries:
## Function
def abc(gamer) :
gamer['name']= 'Roger'
## MAIN
nm={'name':'Sam'}
print(nm)
abc(nm)
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.
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.