Hacker News new | ask | show | jobs
by rockemsockem 1295 days ago
This is indeed correct. Object references themselves in Java/Python are passed by value, which is why the following two code samples do not have the same effect:

  Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
  [GCC 9.4.0] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  >>> def f(d):
  ...     d['foo'] 'bar'}
  ... 
  >>> a = {}
  >>> f(a)
  >>> a
  {'foo': 'bar'}



  Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
  [GCC 9.4.0] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  >>> def f(d):
  ...     d = {'foo': 'bar'}
  ... 
  >>> a = {}
  >>> f(a)
  >>> a
  {}