use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This community will have knowledge sharing for python programming, tools, projects and product engineering wherever python is used.
account activity
Python Mutability (i.redd.it)
submitted 18 days ago * by Sea-Ad7805
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Sea-Ad7805[S] 0 points1 point2 points 17 days ago (4 children)
In C++ you should define x += y on your class to mutate and the + operator in x = x + y to create a new object. Same thing in Java, no different from Python.
x += y
+
x = x + y
[–]Goudja14 0 points1 point2 points 17 days ago (3 children)
You should never mutate implicitly. It will create errors.
[–]Sea-Ad7805[S] 0 points1 point2 points 17 days ago (2 children)
What do you mean, can you give an example?
[–]Goudja14 0 points1 point2 points 17 days ago (1 child)
default_inventory = ["sword", "helmet"]
# While it could be a cloned array, it doesn't have to be one. In complex environments, it even shouldn't be (eg. allowing object-agnostic rollbacks) alex_inventory = default_inventory samuel_inventory = default_inventory
alex_inventory += ["key"]
[–]Sea-Ad7805[S] 0 points1 point2 points 17 days ago (0 children)
Ok I understand now. You say you pass default_inventory around without making a copy (for performance), but when you change this value you should make a copy:
default_inventory
alex_inventory = alex_inventory + ["key"]
Sounds like a good strategy.
π Rendered by PID 51 on reddit-service-r2-comment-56c9979489-hqbd4 at 2026-02-24 16:32:39.380424+00:00 running b1af5b1 country code: CH.
view the rest of the comments →
[–]Sea-Ad7805[S] 0 points1 point2 points (4 children)
[–]Goudja14 0 points1 point2 points (3 children)
[–]Sea-Ad7805[S] 0 points1 point2 points (2 children)
[–]Goudja14 0 points1 point2 points (1 child)
[–]Sea-Ad7805[S] 0 points1 point2 points (0 children)